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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;
struct Name // storing customer name.
{string lastname;
string firstname;
};
struct Address//storing customer address.
{string houseNum;
string streetname;
string city;
string state;
string zip;
};
struct phoneNum //storing customer Number.
{
string phnum;
};
struct custAct// customer account Info.
{
Name custname;
Address custaddr;
phoneNum custphnum;
double actbalance;
string dtlstpymt;
};
vector <custAct> amount;
void menu(string choicenum, custAct alldata,ofstream & outData);
bool choice;
int main()
{
custAct alldata;
ofstream outData;
string choicenum;
vector <custAct> amount;
while (choice==true)
{
cout<<"1. Add customer account\n";
cout<<"2. Display customer accounts\n";
cout<<"3. Store customer accounts\n";
cout<<"4. Quit Program\n";
cin>>choicenum;
menu(choicenum, alldata,outData);
}
return 0;
}
void menu(string choicenum, custAct alldata, ofstream & outData)// i want to overload the custAct alldata
{
if (strcmp(choicenum.c_str(),"1")==0)
{
// enter customer account information;
// store information in a vector.
cout<<"Please enter customer's last name then first name\n.";
cout<<"Please leave a space in between the names\n."; // i want to overload alldata. With this info.
cin>>alldata.custname.lastname>>alldata.custname.firstname;
cout<<" Next enter the customer's address in this order.\n";
cout<<" House number, street Name, city,state, zip and please leave a space in between the\n";
cin>>alldata.custaddr.houseNum>>alldata.custaddr.streetname>>alldata.custaddr.city>>alldata.custaddr.state>>alldata.custaddr.zip;
cout<<"Please enter customer's phone number.\n";
cin>>alldata.custphnum.phnum;
amount.push_back(alldata);
}
if (strcmp(choicenum.c_str(),"2")==0)
{
//sort the vector of accounts info by lastname alphabetically and display on the screen
// one account at a time with appropriate labels.
int i, j;
string index;
if( amount.empty()==true)
cout<<"Error, vector of accounts is empty.";
else
{
for (i=1; i <amount.size(); i++);
{//sorting data that program recieves and places everything in order. but i'm not sure if its working correctly.
index = amount[i].custname.lastname;
j = i;
while ((j > 0) && (amount[j-1].custname.lastname >index))
{
amount[j].custname = amount[j-1].custname;
amount[j].custaddr = amount[j-1].custaddr;
amount[j].custphnum= amount[j-1].custphnum;
amount[j].actbalance= amount[j-1].actbalance;
amount[j].dtlstpymt= amount[j-1].dtlstpymt;
j = j - 1;
}
amount[j].custname.lastname= index;
}
cout<<"black";
}
system("pause");
system("cls");
}
if (strcmp(choicenum.c_str(),"3")==0)
{
//prompt the user for a file name, open that file and essentially do item 2
//but writing the info to the file with out pauses, don't forget to display
// an error message if the vector of accounts is empty, then close the
// file. Overload the insertion operator to send the account info to the file.
char ofile[16];
cout<<"Please enter Filename to save :";// open file to save data
cin>>ofile;
outData.open (ofile);
system("cls");
while (amount())// I want it to loop till it reaches the end of the vector.
{
outData<<alldata[j].custname;
outData<<alldata[j].custaddr;
outData<<alldata[j].custphnum;
outData<<alldata[j].actbalance;
outData<<alldata[j].dtlstpymt;;
}
outData.close();
int i, j;
string index;
if( amount.empty()==true)
cout<<"Error, vector of accounts is empty.";
else
{
for (i=1; i <amount.size(); i++);
{//sorting data that program recieves and places everything in order.
index = amount[i].custname.lastname;
j = i;
while ((j > 0) && (amount[j-1].custname.lastname >index))
{
amount[j].custname = amount[j-1].custname;
amount[j].custaddr = amount[j-1].custaddr;
amount[j].custphnum= amount[j-1].custphnum;
amount[j].actbalance= amount[j-1].actbalance;
amount[j].dtlstpymt= amount[j-1].dtlstpymt;
j = j - 1;
}
amount[j].custname.lastname= index;
}
outData<<[j];
}
if (strcmp(choicenum.c_str(),"4")==0)
{
// exit the program.
// repeat the program until user selects item 4.
choice==false;
}
}
| |