Hello,
I just started C++ and I have this assignment to write. I started writing it but I can't seem to get this one thing and that is how to create a new contact and store it in a file.
I need to know if I used the structure correctly. Also I don't know how you create multiple contacts with a loop. I wouldn't necessarily need the answer from you guys. I just want to know what topics I need to learn to be able to do this.
What do I need to use? That's all I need. I can write the programs for myself.
Also if you guys can tell me how you search for and display a single contact. That would be helpful. Thanks for understanding.
pscha3
Here's the code:
//This is the term project by Chaitanya Pillalamarri. Class CS-102.
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<fstream>
using namespace std;
void Display();
void Delete();
void Create();
void Modify();
void Search();
void Quit(void);
void Restart(int);
int Choice=0;
int main()
{
//The following output statements are the menu.
cout<<""<<endl;
cout<<" Welcome to Virtual Address Book "<<endl;
cout<<"In this book, you have a variety of features to revolutionize your contact lists"<<endl;
cout<<""<<endl;
cout<<"Follow the directions below and chose appropriately from the menu."<<endl;
cout<<""<<endl;
//These are the choices.
cout<<"Please type in the following number to perform the following task:"<<endl;
cout<<" 1 - Display all your contacts\n";
cout<<" 2 - Create a new contact\n";
cout<<" 3 - Edit information for a contact\n";
cout<<" 4 - Search for a contact\n";
cout<<" 5 - Delete contact\n";
cout<<" 6 - Quit this application\n";
cout<<""<<endl;
cout<<""<<endl;
cout<<"If the application asks you to restart the program, just type in '7'."<<endl;
cout<<" 7 - Restarts program"<<endl;
cout<<""<<endl;
//The user choice.
cout<<"ENTER YOUR CHOICE:"<<endl;
cin>>Choice;
switch(Choice)
{
case 1:
{
Display();
break;
}
case 2:
{
Create();
break;
}
case 3:
{
Modify();
break;
}
case 4:
{
Search();
break;
}
case 5:
{
Delete();
break;
}
case 6:
{
Quit();
break;
}
case 7:
{
Restart(Choice);
break;
}
}
}
void Restart(int Choice)
{
while(Choice==7)
main();
}
void Quit(void)
{
cout<<"Goodbye!"<<endl;
exit(0);
}
void Create()
{
char Name1;
Name1=0;
struct Contact
{
char Name;
int Home;
int Business;
int Cell;
int Other;
char Email;
char Address;
int Zip;
char City;
char State;
char Country;
char Job;
char Company;
};
Contact hi;
ofstream Data;
cout<<"This will let you create a new contact."<<endl;
cout<<"Please provide the following information."<<endl;
cout<<"When you do not want to give information for a certain field, just press enter to skip it."<<endl;
//This is the place where the user enters the information.
Data.open("Addressbook.txt",ios::out);
cout<<"Name: ";
cin>>hi.Name;
cout<<""<<endl;
cout<<"Job title: ";
cin>>hi.Job;
cout<<"Company: ";
cin>>hi.Company;
cout<<""<<endl;
cout<<"Address: ";
cin>>hi.Address;
cout<<"City: ";
cin>>hi.City;
cout<<"State: ";
cin>>hi.State;
cout<<"Zip: ";
cin>>hi.Zip;
cout<<"Country: ";
cin>>hi.Country;
cout<<"E-mail: ";
cin>>hi.Email;
cout<<"Home: ";
cin>>hi.Home;
cout<<"Business: ";
cin>>hi.Business;
cout<<"Cell: ";
cin>>hi.Cell;
cout<<"Other: ";
cin>>hi.Other;
Data.close();
}
void Display()
[edit]Code tags added. Learn how to use them before posting again. -Narue[/edit]