Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help for a C program You are to produce an interface that reads a file call

ID: 3811694 • Letter: N

Question

Need help for a C program

You are to produce an interface that reads a file called myContactsList.db and display it and allow for several actions.

You must use 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;

};

*Important

This structure will be written to file. It will hold the phone number and the positions for first, last, company and email. After writing the structure to file you will then write the first name, last name, company name, and email to file. You will keep repeating this for as many times as the user wishes to input information. You should be able to scan the file for contacts based on the phone number.

-­    You must enter either a Last Name or a Company Name for each contact (as well as the phone number and email).

-­    You must check that the phone number has either 7 or 10 digits.

-­   The email address must have the following format: string@string.ccc

Your interface will allow the following to be done:

List all contacts in alphabetical (ascending) order by name (either last name or company name) – only displaying the name. Only 5 names will be displayed at a time. You can tell the interface to scroll down or up one name at a time.

Add a new contact.

Allow one of the contacts to be selected (by the number beside it on the display).

Display the full information for the selected contact.

Change the phone number or email for a selected contact.

Delete a selected contact.

Return to the full contacts list.

Exit the program (all changes to the myContactsList.db file must be written to disk).

Explanation / Answer

The code for given problem is:

#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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote