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
|
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
const int NAME_LEN = 45;
const int ADDR_LEN = 45;
const int CITY_LEN = 20;
const int STATE_LEN = 2;
const int ZIP_LEN = 5;
const int PHONE_LEN = 14;
const int ARRAY_SIZE = 11;
const int DATE_SIZE = 30;
//Data structure for creating records
struct Account
{
char name[NAME_LEN]; // customer name 45 characters
char address[ADDR_LEN]; // address 45 characters
char city[CITY_LEN]; // city 20 characters
char state[STATE_LEN]; // State two letters
char zip[ZIP_LEN]; // zip 5 numbers
char tele[PHONE_LEN]; // telephone number 12 characters
char date[DATE_SIZE]; // date 30 characters
int total[30]; // total array length
double account; // account total
};
//Function Prototypes
void displayMenu();
void setCustomer();
bool rnew = 0;
bool mod = 0;
int main()
{
long fpos;
// Constants for menu choices
const int ENTER_RECORD = 1,
DISPLAY_RECORD = 2,
DELETE_RECORD = 3,
CHANGE_RECORD = 4,
DISPLAY_ALL = 5;
int userChoice = 6;
double filePosition;
do
{
displayMenu();
//Get the users choice
do
{
cout << "Enter your choice (1-6): ";
cin >> userChoice;
}
while (userChoice < 1 || userChoice > 6);
//Process userChoice
switch(userChoice)
{
case ENTER_RECORD:
cin.get();
cout << "\nYou selected Enter a new Customer Account.\n\n";
rnew = 1;
setCustomer();
rnew = 0;
break;
case DISPLAY_RECORD:
cout << "\nYou selected Display a Customer Account.\n\n";
//fpos = search();
break;
case DELETE_RECORD:
cout << "\nYou selected Delete a Customer Account.\n\n";
break;
case CHANGE_RECORD:
cout << "\nYou selected Change a Customer Accounts.\n\n";
break;
case 5:
cout << "\nYou selected Display All Accounts.\n\n";
break;
default: //Anything not between 1-5
break;
}
}
while (userChoice != 6);
return 0;
}
//End of function main
///////////////////////////Function to display menu///////////////////////////
void displayMenu()
{
cout << "\n * * * * A C C O U N T M E N U * * * * \n\n";
cout << "1. Enter a new Customer Account\n";
cout << "2. Display a Customer Account\n";
cout << "3. Delete a Customer Account \n";
cout << "4. Change a Customer Account\n";
cout << "5. Display All Accounts\n";
cout << "6. Exit the Program\n\n";
}
//////////////////////////////////////////////////////////////////
//////////////////////////Function to Set Customer Account///////////////////
void setCustomer()
{
Account customer;
//Open accounts data;
fstream accounts ("accounts.dat",ios::in | ios::out|ios::binary);
cout<<"Enter Data for the Customer:\nName:\t\t\t";
cin.getline(customer.name,NAME_LEN);
cout<<"Address:\t\t";
cin.getline(customer.address,ADDR_LEN);
cout<<"City:\t\t\t";
cin.getline(customer.city,CITY_LEN);
cout<<"State:\t\t\t";
cin.getline(customer.state,STATE_LEN);
cout<<"Zip Code:\t\t";
cin.getline(customer.zip,ZIP_LEN);
cout<<"Telephone Number:\t";
cin.getline(customer.tele,PHONE_LEN);
cout<<"Date of last Payment:\t";
cin.getline(customer.date,DATE_SIZE);
do{
cout<<"Account Balance:\t";
cin.getline(customer.total,30);
if(customer.total<0)
cout<<"Invalid Balance!\n";
}while(customer.total<0); //data validation
//write new record
accounts.write(reinterpret_cast<char *>(&customer),sizeof(customer));
//close file
accounts.close;
}
///////////////////////////////////////////////////////////////////////////////
|