Jan 3, 2014 at 3:51pm UTC
I'm trying to make an address book program where the user can create as many addresses as he/she wants. The problem is, I have not the slightest idea on how to make it so that the number of addresses can fluxuate as the user creates and deletes entries.
heres my code so far:
(sorry for wall of code)
[code]
#include <string>
#include <iostream>
using namespace std;
int c;
int total_a = 0;
string user_c;
class addr
{
public:
addr()
{
}
addr(string first_n, string last_n, double p_numb, char sex)
{
f_name = first_n;
l_name = last_n;
phone = p_numb;
gender = sex;
}
~addr()
{
delete f_name;
delete l_name;
delete phone;
delete gender;
}
private:
string f_name;
string l_name;
double phone;
char gender;
};
string intro(char first);
string intro(char first)
{
if (first == 'f')
{
cout<<"create a new address"<<endl;
cout<<"browse the addresses"<<endl;
cout<<"delete an address"<<endl;
cout<<"exit the program"<<endl;
}
if (first == 'n')
{
cout<<"create"<<endl;
cout<<"browse"<<endl;
cout<<"delete"<<endl;
cout<<"exit"<<endl;
}
cin >> user_c;
return user_c;
}
void decoder(string command);
void decoder(string command)
{
if (command == "create")c = 1;
else if (command == "browse")c = 2;
else if (command == "delete")c = 3;
else if (command == "exit")c = 4;
}
void pr_create();
void pr_create()
{
total_a += 1;
}
void pr_browse();
void pr_browse()
{
}
void pr_delete();
void pr_delete()
{
if (total_a == 0)
{
cout<<"you don't have any addresses to delete!" <<endl;
}
total_a -= 1;
}
int execute(int c);
int execute(int c)
{
switch (c)
{
case 1:
pr_create();
return 1;
break;
case 2:
pr_browse();
return 1;
break;
case 3:
pr_delete();
return 1;
break;
case 4:
return 0;
break;
default:
return 0;
break;
}
}
int main ()
{
bool pr_run = true;
while (pr_run == true)
{
if (total_a == 0)
{
cout<<"you have no current addresses"<<endl;
intro('f');
}
else
{
intro('n');
}
decoder(user_c);
execute(c);
if (execute(c) == 0){
cout << "closing..." <<endl;
pr_run = false;
}
}
return 0;
}
[code]
Last edited on Jan 3, 2014 at 3:52pm UTC