Server IP : 172.16.15.8 / Your IP : 18.119.159.196 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/acyurksaitis/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Assignment 5 // // Author: Raichel Link // Instructor: Dr. Wang // Due: Feb. 27, 2007 // // Goal: Display menus that will allow the user to enter // customer data, change given data, search through // the data, and print the data. // // File name: assignment5.cpp // Compiling: g++ assignment5.cpp -o assignment5.out // Excution: ./assignment5.out // #include <iostream> #include <iomanip> #include <cmath> #include <string> #include <fstream> using namespace std; const int MAX = 2; struct Date { int month; int day; int year; }; struct Customer { string name; float balance; Date lastPay; }; // prototypes - type & fun. void menu(); void enter(Customer[]); void change(Customer[]); void print(Customer[]); void search(Customer[]); int main() { char select, dummy; Customer account[MAX]; system("clear"); menu(); cin >> select; while( select != 'q' && select != 'Q') { if( tolower(select) == 'e') enter(account); else if( tolower(select) == 'c') change(account); else if( tolower(select) == 'p') print(account); else if( tolower(select) == 's') search(account); cout << endl << endl; menu(); cin >> select; } cout << "Done." << endl; return 0; } void menu() { cout << "\t MENU\n"; cout << "\t======\n"; cout << "E - Enter customer data\n"; cout << "C - Change customer data\n"; cout << "P - Print customer data\n"; cout << "S - Search customers by name\n"; cout << "Q - Quit \n\n"; cout << "Your selection: "; } void enter(Customer client[]) { char dummy; bool go = true; for(int i=0; i<MAX; i++) { cin.get(dummy); while(go) { cout << "\n\nFor customer " << i+1 << ":\n"; cout << "Name: "; getline(cin, client[i].name); if(client[i].name.empty() == false) go = false; } go = true; while(go) { cout << "Balance: "; cin >> client[i].balance; if(client[i].balance > 0) go = false; } go = true; while(go) { cout << "Month of Last Payment: "; cin >> client[i].lastPay.month; if(client[i].lastPay.month >= 1 && client[i].lastPay.month <= 12) go = false; } go = true; while(go) { cout << "Day of Last Payment: "; cin >> client[i].lastPay.day; if(client[i].lastPay.day >= 1 && client[i].lastPay.day <= 31) go = false; } go = true; while(go) { cout << "Year of Last Payment: "; cin >> client[i].lastPay.year; if(client[i].lastPay.year >= 1900 && client[i].lastPay.year <= 2007) go = false; } go = true; cout << endl; } } void change(Customer client[]) { int num; char ch, dummy; cout << "What is the customer number of the account you wish to change? "; cin >> num; cout << endl; cout << "Enter the letter of the info you wish to change:\n"; cout << "a -- customer " << num << "'s name\n"; cout << "b -- customer " << num << "'s balance\n"; cout << "c -- customer " << num << "'s Month of Last Payment\n"; cout << "d -- customer " << num << "'s Day of Last Payment\n"; cout << "e -- customer " << num << "'s Year of Last Payment\n"; cout << endl << "Your choice: "; cin >> ch; cout << endl; if(ch == 'a') { cin.get(dummy); cout << "Enter the new name: "; getline(cin, client[num-1].name); cout << "Customer " << num << " is now under the name " << client[num-1].name << endl; } if(ch == 'b') { cin.get(dummy); cout << "Enter the new balance: "; cin >> client[num-1].balance; cout << "Customer " << num << " now has a balance of: " << client[num-1].balance << endl; } if(ch == 'c') { cin.get(dummy); cout << "Enter the new month of last payment: "; cin >> client[num-1].lastPay.month; cout << "Customer " << num << "'s last payment was in the month of: " << client[num-1].lastPay.month << endl; } if(ch == 'd') { cin.get(dummy); cout << "Enter the new day of last payment: "; cin >> client[num-1].lastPay.day; cout << "Customer " << num << "'s last payment was on the day of: " << client[num-1].lastPay.day << endl; } if(ch == 'e') { cin.get(dummy); cout << "Enter the new year of last payment: "; cin >> client[num-1].lastPay.year; cout << "Customer " << num << "'s lasy payment was in the year of: " << client[num-1].lastPay.year << endl; } } void print(Customer client[]) { int num; cout << "What is the number of the customer whose data you would like to print (to print all data, type -1)? "; cin >> num; if(num != -1) { cout << "\n Information for customer " << num-1 << ":\n"; cout << "Name: \t\t" << client[num-1].name << endl; cout << "Balance: \t" << client[num-1].balance << endl; cout << "Month of Last Payment: " << client[num-1].lastPay.month << endl; cout << "Day of Last Payment: " << client[num-1].lastPay.day << endl; cout << "Year of Last Payment: " << client[num-1].lastPay.year << endl; } if(num == -1) { for(int i=0; i < MAX; i++) { cout << "\nInformation for customer " << i+1 << ":\n"; cout << "Name: \t\t" << client[i].name << endl; cout << "Balance: \t" << client[i].balance << endl; cout << "Month of Last Payment: " << client[i].lastPay.month << endl; cout << "Day of Last Payment: " << client[i].lastPay.day << endl; cout << "Year of Last Payment: " << client[i].lastPay.year << endl; } cout << endl << endl; } } void search(Customer client[]) { string search; int num = 0, x; char dummy; cout << "What is the name of the customer you're looking for: "; cin.get(dummy); //"\n" getline(cin, search); for(int i=0; i < MAX; i++) { x = client[i].name.find(search, 0); if(x != -1) { cout << "\nInformation for customer " << i+1 << ":\n"; cout << "Name: \t\t" << client[i].name << endl; cout << "Balance: \t" << client[i].balance << endl; cout << "Month of Last Payment: " << client[i].lastPay.month << endl; cout << "Day of Last Payment: " << client[i].lastPay.day << endl; cout << "Year of Last Payment: " << client[i].lastPay.year << endl; num = num + 1; } } if(num == 0) cout << "No customer matches your search." << endl; }