address book class members
Jan 4, 2014 at 10:46pm UTC
How can i make it so that a user can create as many new entries as theywant, then delete any that they don't need anymore. I know this has to do with construtors and deconstructors, but i don't know how to get them to work. here's my code as of now.
thanksin advance
-ASCII14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
//
// main.cpp
// address book
//
// Copyright 2014 jesse smith. All rights reserved.
#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;
}
Topic archived. No new replies allowed.