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
|
/*
The program should use an array of at least 10 structures,
it should let the user enter data into the array,
change the contents of any element, and display all the data
stored in the array. The program should have a menu-driven user
interface.
Input validation: when the data for a new account is entered,
be sure the user enters data for all the field. No negative
account balances should be entered.
Add a function that allows the user to search the structure
array for a particular customer’s account. It should accept part
of the customer’s name as an argument and then search for an
account with a name that matches it. All accounts that match
should be displayed. Of no account matches, a message saying
so should be displayed.
*/
#include <iostream>
#include <string>
using namespace std;
struct Customer{
string Name;
string Address;
string City;
string State;
string ZIP;
string Pnumber; //phone number
double aBalance; //account balance
string DataOfLastPaym;
};
void EnterChangeAccInfo(Customer&);
void showInfo(Customer);
//void Search();
const int SIZE = 10;
int main()
{
int answer;
//here I started to think, maybe I need to have parts of the info initialized?
Customer aArrayOfCustomers[SIZE];
aArrayOfCustomers[0].Name = "Jake Smith";
aArrayOfCustomers[0].Address = "888 Forest Hill";
aArrayOfCustomers[0].City = "Peoria";
aArrayOfCustomers[0].State = "IL";
aArrayOfCustomers[0].ZIP = "61550";
aArrayOfCustomers[0].Pnumber = "888-712-9881";
aArrayOfCustomers[0].aBalance = 800.25;
aArrayOfCustomers[0].DataOfLastPaym = "08/15/2011";
// Display a menu.
cout << "---------- MENU ----------------------" << endl;
cout << "1. Enter new account information |\n";
cout << "2. Change account information |\n";
cout << "3. Display all account information |\n";
cout << "4. Exit the program |\n";
cout << "--------------------------------------" << endl;
cout << endl;
while(answer > 4 || answer < 1){
cout << "Choose 1-4: ";
cin >> answer;
}
cout << endl;
while(answer != 4){
switch(answer){
case 1:{
//new account info.
EnterChangeAccInfo(aArrayOfCustomers[0]);
}
break;
case 2:{
//change account info.
}
break;
case 3:{
//display info
showInfo(aArrayOfCustomers[0]); // when I display info it runs infinite?
}
break;
default: break;
}
}
return 0;
}
// Function getInfo gets account information from the user
//and stores it in the parameter, which is a Customer structure
//reference variable.
void EnterChangeAccInfo(Customer &a){
cout << "Enter customer's name: ";
cin.ignore();
getline(cin,a.Name);
cout << "Address: ";
getline(cin,a.Address);
cout << "City: ";
cin >> a.City;
cout << "State: ";
cin >> a.State;
cout << "ZIP: ";
cin >> a.ZIP;
cout << "Phone Number: ";
cin >> a.Pnumber;
cout << "Account Balance: ";
cin >> a.aBalance;
cout << "Date of Last Payment: ";
cin.ignore();
getline(cin,a.DataOfLastPaym);
}
// Function showInfo displays the customer's name, address,
//account balance, and date of last payment.
//The information is passed into the c structure.
void showInfo(Customer display){
cout << "\n --- Data for " <<display.Name <<" ---\n";
cout << "\nAddress:\t" << display.Address << ", " << display.City << ", " << display.State << ", " << display.ZIP;
cout << "\nTelephone:\t" << display.Pnumber;
cout << "\nLast Payment:\t" << display.DataOfLastPaym;
cout << "\nAccount balance:\t" << display.aBalance << endl;
}
// Search the array for account
/*void Search(string theName){
for(int i = 0; i < SIZE; i++){
if(theName == info[i]){ //issue here
//enter what to do if account found
cout << "Name: " << info[i].Name << endl;
cout << "Address: "<< info[i].Address << endl;
cout << "City: " << info[i].City << endl;
cout << "State: " << info[i].State << endl;
cout << "ZIP: " << info[i].ZIP << endl;
cout << "Phone Number: " << info[i].Pnumber << endl;
cout << "Account Balance: " << info[i].aBalance << endl;
cout << "Date of Last Payment: " << info[i].DataOfLastPaym << endl;
break;
}else{
cout << "Account not found" << endl;
}
}
}
*/
|