The code below shows a Contact Management System. Without using the Class concept, migrating the C code project (structural mode) to the C++ environment. ​​​​​​​Original Code: You must convert this C file into C++ environments CODE: CONTACT MANAGEMENT SYSTEM #include #include #include #include #include #include struct contact {  long ph;  char name[20],add[20],email[30]; } list; char query[20],name[20]; FILE *fp, *ft; int i,n,ch,l,found; int main() { main:  system("cls"); /* ************Main menu *********************** */  printf("\n\t **** Welcome to Contact Management System ****");  printf("\n\n\n\t\t\tMAIN MENU\n\t\t=====================\n\t\t[1] Add a new Contact\n\t\t[2] List all Contacts\n\t\t[3] Search for contact\n\t\t[4] Edit a Contact\n\t\t[5] Delete a Contact\n\t\t[0] Exit\n\t\t=================\n\t\t");  printf("Enter the choice:");  scanf("%d",&ch);  switch(ch)  {  case 0:  printf("\n\n\t\tAre you sure you want to exit?");  break;  /* *********************Add new contacts************ */  case 1:  system("cls");  fp=fopen("contact.dll","a");  for (;;)  {  fflush(stdin);  printf("To exit enter blank space in the name input\nName (Use identical):");  scanf("%[^\n]",&list.name);  if(stricmp(list.name,"")==0 || stricmp(list.name," ")==0)  break;  fflush(stdin);  printf("Phone:");  scanf("%ld",&list.ph);  fflush(stdin);  printf("address:");  scanf("%[^\n]",&list.add);  fflush(stdin);  printf("email address:");  gets(list.email);  printf("\n");  fwrite(&list,sizeof(list),1,fp);  }  fclose(fp);  break;  /* *********************list of contacts************************* */  case 2:  system("cls");  printf("\n\t\t================================\n\t\t\tLIST OF CONTACTS\n\t\t================================\n\nName\t\tPhone No\t Address\t\tE-mail ad.\n=============================================================== ==\n\n");  for(i=97; i<=122; i=i+1)  {  fp=fopen("contact.dll","r");  fflush(stdin);  found=0;  while(fread(&list,sizeof(list),1,fp)==1)  {  if(list.name[0]==i || list.name[0]==i-32)  {  printf("\nName\t: %s\nPhone\t: %ld\nAddress\t: %s\nEmail\t: %s\n",list.name,  list.ph,list.add,list.email);  found++;  }  }  if(found!=0)  { printf("=========================================================== [%c]-(%d)\n\n",i-32,found);  getch();  }  fclose(fp);  }  break;  /* *******************search contacts********************** */  case 3:  system("cls");  do  {  found=0;  printf("\n\n\t..::CONTACT SEARCH\n\t===========================\n\t..::Name of contact to search: ");  fflush(stdin);  scanf("%[^\n]",&query);  l=strlen(query);  fp=fopen("contact.dll","r");  system("cls");  printf("\n\n..::Search result for '%s' \n===================================================\n",query);  while(fread(&list,sizeof(list),1,fp)==1)  {  for(i=0; i<=l; i++)  name[i]=list.name[i];  name[l]='\0';  if(stricmp(name,query)==0)  {  printf("\n..::Name\t: %s\n..::Phone\t: %ld\n..::Address\t: %s\n..::Email\t: %s\n",list.name,list.ph,list.add,list.email);  found++;  if (found%4==0)  {  printf("..::Press any key to continue...");  getch();  }  }  }  if(found==0)  printf("\n..::No match found!");  else  printf("\n..::%d match(s) found!",found);  fclose(fp);  printf("\n ..::Try again?\n\n\t[1] Yes\t\t[0] No\n\t");  scanf("%d",&ch);  }  while(ch==1);  break;  /* *********************edit contacts************************/  case 4:  system("cls");  fp=fopen("contact.dll","r");  ft=fopen("temp.dat","w");  fflush(stdin);  printf("..::Edit contact\n===============================\n\n\t..::Enter the name of contact to edit:");  scanf("%[^\n]",name);  while(fread(&list,sizeof(list),1,fp)==1)  {  if(stricmp(name,list.name)!=0)  fwrite(&list,sizeof(list),1,ft);  }  fflush(stdin);  printf("\n\n..::Editing '%s'\n\n",name);  printf("..::Name(Use identical):");  scanf("%[^\n]",&list.name);  fflush(stdin);  printf("..::Phone:");  scanf("%ld",&list.ph);  fflush(stdin);  printf("..::address:");  scanf("%[^\n]",&list.add);  fflush(stdin);  printf("..::email address:");  gets(list.email);  printf("\n");  fwrite(&list,sizeof(list),1,ft);  fclose(fp);  fclose(ft);  remove("contact.dll");  rename("temp.dat","contact.dll");  break;  /* ********************delete contacts**********************/  case 5:  system("cls");  fflush(stdin);  printf("\n\n\t..::DELETE A CONTACT\n\t==========================\n\t..::Enter the name of contact to delete:");  scanf("%[^\n]",&name);  fp=fopen("contact.dll","r");  ft=fopen("temp.dat","w");  while(fread(&list,sizeof(list),1,fp)!=0)  if (stricmp(name,list.name)!=0)  fwrite(&list,sizeof(list),1,ft);  fclose(fp);  fclose(ft);  remove("contact.dll");  rename("temp.dat","contact.dll");  break;  default:  printf("Invalid choice");  break;  }  printf("\n\n\n..::Enter the Choice:\n\n\t[1] Main Menu\t\t[0] Exit\n");  scanf("%d",&ch);  switch (ch)  {  case 1:  goto main;  case 0:  break;  default:  printf("Invalid choice");  break;  }  return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The code below shows a Contact Management System. Without using the Class concept, migrating the C code project (structural mode) to the C++ environment.

​​​​​​​Original Code:
You must convert this C file into C++ environments
CODE: CONTACT MANAGEMENT SYSTEM
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdlib.h>
#include<dos.h>
struct contact
{
 long ph;
 char name[20],add[20],email[30];
} list;
char query[20],name[20];
FILE *fp, *ft;
int i,n,ch,l,found;
int main()
{
main:
 system("cls"); /* ************Main menu
*********************** */
 printf("\n\t **** Welcome to Contact Management System ****");
 printf("\n\n\n\t\t\tMAIN
MENU\n\t\t=====================\n\t\t[1] Add a new Contact\n\t\t[2]
List all Contacts\n\t\t[3] Search for contact\n\t\t[4] Edit a
Contact\n\t\t[5] Delete a Contact\n\t\t[0]
Exit\n\t\t=================\n\t\t");
 printf("Enter the choice:");
 scanf("%d",&ch);
 switch(ch)
 {
 case 0:
 printf("\n\n\t\tAre you sure you want to exit?");
 break;
 /* *********************Add new contacts************ */
 case 1:
 system("cls");
 fp=fopen("contact.dll","a");
 for (;;)
 {
 fflush(stdin);
 printf("To exit enter blank space in the name
input\nName (Use identical):");
 scanf("%[^\n]",&list.name);
 if(stricmp(list.name,"")==0 || stricmp(list.name,"
")==0)
 break;
 fflush(stdin);
 printf("Phone:");
 scanf("%ld",&list.ph);
 fflush(stdin);
 printf("address:");
 scanf("%[^\n]",&list.add);
 fflush(stdin);
 printf("email address:");
 gets(list.email);
 printf("\n");
 fwrite(&list,sizeof(list),1,fp);
 }
 fclose(fp);
 break;
 /* *********************list of
contacts************************* */
 case 2:
 system("cls");
 printf("\n\t\t================================\n\t\t\tLIST
OF CONTACTS\n\t\t================================\n\nName\t\tPhone
No\t Address\t\tE-mail
ad.\n===============================================================
==\n\n");
 for(i=97; i<=122; i=i+1)
 {
 fp=fopen("contact.dll","r");
 fflush(stdin);
 found=0;
 while(fread(&list,sizeof(list),1,fp)==1)
 {
 if(list.name[0]==i || list.name[0]==i-32)
 {
 printf("\nName\t: %s\nPhone\t: %ld\nAddress\t:
%s\nEmail\t: %s\n",list.name,
 list.ph,list.add,list.email);
 found++;
 }
 }
 if(found!=0)
 {

printf("===========================================================
[%c]-(%d)\n\n",i-32,found);
 getch();
 }
 fclose(fp);
 }
 break;
 /* *******************search contacts**********************
*/
 case 3:
 system("cls");
 do
 {
 found=0;
 printf("\n\n\t..::CONTACT
SEARCH\n\t===========================\n\t..::Name of contact to
search: ");
 fflush(stdin);
 scanf("%[^\n]",&query);
 l=strlen(query);
 fp=fopen("contact.dll","r");
 system("cls");
 printf("\n\n..::Search result for '%s'
\n===================================================\n",query);
 while(fread(&list,sizeof(list),1,fp)==1)
 {
 for(i=0; i<=l; i++)
 name[i]=list.name[i];
 name[l]='\0';
 if(stricmp(name,query)==0)
 {
 printf("\n..::Name\t: %s\n..::Phone\t:
%ld\n..::Address\t: %s\n..::Email\t:
%s\n",list.name,list.ph,list.add,list.email);
 found++;
 if (found%4==0)
 {
 printf("..::Press any key to continue...");
 getch();
 }
 }
 }
 if(found==0)
 printf("\n..::No match found!");
 else
 printf("\n..::%d match(s) found!",found);
 fclose(fp);
 printf("\n ..::Try again?\n\n\t[1] Yes\t\t[0] No\n\t");
 scanf("%d",&ch);
 }
 while(ch==1);
 break;
 /* *********************edit
contacts************************/
 case 4:
 system("cls");
 fp=fopen("contact.dll","r");
 ft=fopen("temp.dat","w");
 fflush(stdin);
 printf("..::Edit
contact\n===============================\n\n\t..::Enter the name of
contact to edit:");
 scanf("%[^\n]",name);
 while(fread(&list,sizeof(list),1,fp)==1)
 {
 if(stricmp(name,list.name)!=0)
 fwrite(&list,sizeof(list),1,ft);
 }
 fflush(stdin);
 printf("\n\n..::Editing '%s'\n\n",name);
 printf("..::Name(Use identical):");
 scanf("%[^\n]",&list.name);
 fflush(stdin);
 printf("..::Phone:");
 scanf("%ld",&list.ph);
 fflush(stdin);
 printf("..::address:");
 scanf("%[^\n]",&list.add);
 fflush(stdin);
 printf("..::email address:");
 gets(list.email);
 printf("\n");
 fwrite(&list,sizeof(list),1,ft);
 fclose(fp);
 fclose(ft);
 remove("contact.dll");
 rename("temp.dat","contact.dll");
 break;
 /* ********************delete
contacts**********************/
 case 5:
 system("cls");
 fflush(stdin);
 printf("\n\n\t..::DELETE A
CONTACT\n\t==========================\n\t..::Enter the name of
contact to delete:");
 scanf("%[^\n]",&name);
 fp=fopen("contact.dll","r");
 ft=fopen("temp.dat","w");
 while(fread(&list,sizeof(list),1,fp)!=0)
 if (stricmp(name,list.name)!=0)
 fwrite(&list,sizeof(list),1,ft);
 fclose(fp);
 fclose(ft);
 remove("contact.dll");
 rename("temp.dat","contact.dll");
 break;
 default:
 printf("Invalid choice");
 break;
 }
 printf("\n\n\n..::Enter the Choice:\n\n\t[1] Main Menu\t\t[0]
Exit\n");
 scanf("%d",&ch);
 switch (ch)
 {
 case 1:
 goto main;
 case 0:
 break;
 default:
 printf("Invalid choice");
 break;
 }
 return 0;
}

Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education