Question

Write this in a C program please.

Structures on Disk The Problem Your task is to write a program that stores and retrieves structures in a file on disk. The file of structures must remain on the disk once your program ends. You should be able to store structures to the file and retrieve from the file after restarting the program The record that you will be writing to file has the following structure: struct contact unsigned long phone number; long first name posn long last name posn long company name posn; long email posn long next first name posn last name posn, company name posn, and email posn are the position in the file of the First Name, Last Name, Company Name, and Email variable strings. These e required for writing and reading the information to be stored. When you write the structures on disk you will need to store the First Name, Last Name, Company Name, and Email strings separately from the contact structure. I n the file you wi write the contact structure first followed by the First Name, Last Name, Company Name, and Email strings (if they exist). The only required information is the Phone Number -all other information is optional The position next stores the location in the file where the next contact record is stored The file can contain any number of records and associated strings. The name of the file will be myContactList.db and if the file does not exist then you program must create it Interface (input and output) Your program will have an input interface that does the following Do you wish to enter a new contact (Yes or No)? First Name: Last Name: Company Name Phone Number (enter only numbers): Email:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

c++ code for the given problem is as follows:-

#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
struct contact
{
unsigned long phone_number;
long first_name_posn;
long last_name_posn;
long company_name_posn;
long email_posn;
struct contact *next;
}*head;
class ll
{
public:
ll()
{head=NULL;}
contact* createnode(long phone_number1,long first_name_posn1,
long last_name_posn1,
long company_name_posn1,
long email_posn1);
void last(long phone_number1,long first_name_posn1,
long last_name_posn1,
long company_name_posn1,
long email_posn1);
void display();// Append node (to add new node at last position)
};
contact* ll::createnode(long phone_number1,long first_name_posn1,
long last_name_posn1,
long company_name_posn1,
long email_posn1)
{
struct contact * temp,* ptr;
temp=new(struct contact);
if(temp==NULL)
cout<<"no memory allocated"<<endl;
else
{
temp->phone_number=phone_number1;
temp->first_name_posn=first_name_posn1;
temp->last_name_posn=last_name_posn1;
temp->company_name_posn=first_name_posn1;
temp->email_posn=email_posn1;
temp->next=NULL;
return temp;
}
}
void ll::last(long phone_number1,long first_name_posn1,
long last_name_posn1,
long company_name_posn1,
long email_posn1)
{
struct contact *temp,*p;
temp=createnode(phone_number1,first_name_posn1,last_name_posn1,company_name_posn1,email_posn1);
if (head==NULL)
{
temp->phone_number=phone_number1;
temp->first_name_posn=first_name_posn1;
temp->last_name_posn=last_name_posn1;
temp->company_name_posn=first_name_posn1;
temp->email_posn=email_posn1;
head=temp;
}
else
{
p=head;
while(p->next!=NULL)
{
p=p->next;
}
p->next=temp;
temp->next=NULL;
}
}
void ll::display()
{
struct contact *ptr;
ptr=head;
if(head==NULL)
cout<<"empty"<<endl;
else
{
while(ptr!=NULL)
{
cout<<ptr->phone_number<<" "<<ptr->first_name_posn<<" "<<ptr->last_name_posn<<" "<<ptr->company_name_posn<<" "<<ptr->email_posn<<endl;;
ptr=ptr->next;
}
cout<<" "<<endl;
}
}
int main()
{
   ll l0;
   int k,t=0;
   loop: cout<<"if you wish to enter another contact press 1 "<<endl;
   cin>>k;
   if(k==1)
   {
       long phone_number1;
       long first_name_posn1;
long last_name_posn1;
long company_name_posn1;
long email_posn1;
       cout<<"Enter:"<<endl;
       cout<<"first name:"<<endl;
       cin>>first_name_posn1;
       cout<<"Last name:"<<endl;
       cin>>last_name_posn1;
       cout<<"company name: "<<endl;
       cin>>company_name_posn1;
       cout<<"phone number"<<endl;
       cin>>phone_number1;
       cout<<"email:"<<endl;
       cin>>email_posn1;
      
       l0.last(phone_number1,first_name_posn1,last_name_posn1,company_name_posn1,email_posn1);  
       t++;
       }
       if(t==1)
       {
           goto loop;
           }
       l0.display();
   return 0;
}

note:- in c just use printf and scanf in place of cout and cin and the remaining program remains same and change the header file to #include<stdio.h>

Output:-

CAProgram Files (x86)\Dev-CpplConsolePauser.exe first name 5646 Last name 6465 company name 468 phone number 565 email 5616 i

Add a comment
Know the answer?
Add Answer to:
Write this in a C program please. Structures on Disk The Problem Your task is to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program (attach source file of your program and include its source code your answer...

    Write a program (attach source file of your program and include its source code your answer script too ) that does the following defines a structure for a phonebook contact with at least the following members: contact_name, phone_number, email. If the phonebook is empty it will prompt user to create list If not empty the program will list all the phonebook contacts and details . [HINT] Implement a linked list and traverse the linked list                                                     [20]

  • CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE...

    CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE IF POSSIBLE!! General Description: Write a program that allows the user to enter data on their friends list. The list holds a maximum of 10 friends, but may have fewer. Each friend has a name, phone number, and email address. The program first asks the user to enter the number of friends (1-10). You are not required to validate the entry, but you may...

  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

  • Write a program that does the following in Python Code: Stores the following three lists: last_name...

    Write a program that does the following in Python Code: Stores the following three lists: last_name = ["Smith", "Jones", "Williams", "Bailey", "Rogers", "Pyle", "Rossington"] first_name =["Lisa", "Bill", "Jay", "Sally", "Walter","Jake","Gary"] phone_number =["240-233-1921", "301-394-2745", "571-321-8934", "703-238-3432", "703-947-9987", "301-945-3593", "240-671-3221"] Has a function named combine_lists() that takes in last_names, first_names and phone_numbers as lists and returns a dictionary called phone_book that uses last_name as the key and a list consisting of first_name and phone_number. Has a main function that iterates through the...

  • Write a C program to store the first name, the age and the exam mark of...

    Write a C program to store the first name, the age and the exam mark of 5 students by using an array of structures. Print the information stored in the structure array on the screen

  • ASSIGNMENT: Student Data Write a program that uses two structures Name and Student to store the following information for multiple students 1. Create a NAME structure that consists of o First Name, M...

    ASSIGNMENT: Student Data Write a program that uses two structures Name and Student to store the following information for multiple students 1. Create a NAME structure that consists of o First Name, Middle Initial, and oLast Name. 2. Create a STUDENT structure that contains student information (Include the NAME structure within the Student information structure): o Name o email o Program (an enum type containing programs such as CSCI, DBMS, INFM, SDEV) ASSIGNMENT: Student Data Write a program that uses...

  • Write a code using python to make an Agenda that can store values such as Name,...

    Write a code using python to make an Agenda that can store values such as Name, Address and Phone number of 10 digits Name format First, Last Address Format Street, Number Zip City ST. Country phone format (###) ###-#### This program should give the option of adding a new contact or Display all the contacts you have stored by typing New Contact or Display Contacts

  • In Language = C Concepts for this are (malloc/realloc, structs, and stdin/fgets/getc/scanf) Description Your program will...

    In Language = C Concepts for this are (malloc/realloc, structs, and stdin/fgets/getc/scanf) Description Your program will ask the user to type in the following information: First Name: Last Name: ID#: Email: The program will terminate when a single . is entered as a First Name. This information will be stored in the following structure type: struct student { int recordCount; char *firstName; char *lastName; char *id; char *email; } recordCount is a number assigned at the beginning of the program...

  • Write a program (C++) that shows Game sales. The program should use a structure to store...

    Write a program (C++) that shows Game sales. The program should use a structure to store the following data about the Game sale: Game company Type of Game (Action, Adventure, Sports etc.) Year of Sale Sale Price The program should use an array of at least 3 structures (3 variables of the same structure). It should let the user enter data into the array, change the contents of any element and display the data stored in the array. The program...

  • Write the program in C The following statistics for cities of the Vege country are stored...

    Write the program in C The following statistics for cities of the Vege country are stored in a file: Name: a string of characters less than 15 characters long. Population: an integer value. Area: square miles of type double Write a program that: asks and gets the name of the input file from the user. Read the contents of the file into an array length 10 of structures -ask the user for the name of a city (less than 15...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT