If you are doing this as a group project, include a summary of what each member
ID: 3776235 • Letter: I
Question
If you are doing this as a group project, include a summary of what each member established. If both are working on coding what each one has established and which code each person write? At the end submit your documentation (Pseducode, source code, and input/output).This program should be designed and written by a team of students. Here are some suggestions:
a. One student may work on a single class. b. The requirements of the program should be analyzed so each student takes about the same work load. c. The parameter and return types of each function and class member function should be decided in advanced. d. The program will be best implemented as a multi-file program, (header file, main program,..) e. You need to print all output to an output file and submit it to instructor during final exam. Design a generic class or structure to store the following information about a customer account: • Name • Address • City , State , and Zip • Telephone Number • Account balance • Date of last payment The class or structure should be used to store customer account recors in a file. The program should have a menu that lets the user perform the following operations: • Enter new records into the file • Search for a particular customer’s record and display it. • Search for a particular customer’s record and delete it. • Search for a particular customer’s record and change it. • Display the contents of the entire file Input validation: When the information for new account is entered, be sure the user enters data for all the fields. No negative account balance should be entered. If you are doing this as a group project, include a summary of what each member established. If both are working on coding what each one has established and which code each person write? At the end submit your documentation (Pseducode, source code, and input/output).
This program should be designed and written by a team of students. Here are some suggestions:
a. One student may work on a single class. b. The requirements of the program should be analyzed so each student takes about the same work load. c. The parameter and return types of each function and class member function should be decided in advanced. d. The program will be best implemented as a multi-file program, (header file, main program,..) e. You need to print all output to an output file and submit it to instructor during final exam. Design a generic class or structure to store the following information about a customer account: • Name • Address • City , State , and Zip • Telephone Number • Account balance • Date of last payment The class or structure should be used to store customer account recors in a file. The program should have a menu that lets the user perform the following operations: • Enter new records into the file • Search for a particular customer’s record and display it. • Search for a particular customer’s record and delete it. • Search for a particular customer’s record and change it. • Display the contents of the entire file Input validation: When the information for new account is entered, be sure the user enters data for all the fields. No negative account balance should be entered. If you are doing this as a group project, include a summary of what each member established. If both are working on coding what each one has established and which code each person write? At the end submit your documentation (Pseducode, source code, and input/output).
This program should be designed and written by a team of students. Here are some suggestions:
a. One student may work on a single class. b. The requirements of the program should be analyzed so each student takes about the same work load. c. The parameter and return types of each function and class member function should be decided in advanced. d. The program will be best implemented as a multi-file program, (header file, main program,..) e. You need to print all output to an output file and submit it to instructor during final exam. Design a generic class or structure to store the following information about a customer account: • Name • Address • City , State , and Zip • Telephone Number • Account balance • Date of last payment The class or structure should be used to store customer account recors in a file. The program should have a menu that lets the user perform the following operations: • Enter new records into the file • Search for a particular customer’s record and display it. • Search for a particular customer’s record and delete it. • Search for a particular customer’s record and change it. • Display the contents of the entire file Input validation: When the information for new account is entered, be sure the user enters data for all the fields. No negative account balance should be entered.
Explanation / Answer
#include "AlterRecords.h"
#include "Validation.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
void splashScreen();
void clearScreen();
void searchRecord(struct CustomerAccount);
void displayContents(struct CustomerAccount);
void newRecord(struct CustomerAccount);
void addPayment(struct CustomerAccount);
bool checkYN(std::string&);
void changeRecord(struct CustomerAccount);
void removeRecord(struct CustomerAccount);
void userInput(struct CustomerAccount, long);
const int NAME_SIZE = 32, ADDRESS_SIZE = 40, CITY_SIZE = 32, STATE_SIZE = 3, TELE_SIZE = 13, DATE_SIZE = 11;
struct CustomerAccount {
char name[NAME_SIZE]; //Holds the name of the customer
char address[ADDRESS_SIZE]; //Holds the address of the customer
char state[STATE_SIZE]; //Customer's current state
char city[CITY_SIZE]; //Customer's current city
int zip; //Customer's zip
char telephone[TELE_SIZE]; //Customer's telephone number (EX: 555-555-5555)
double accountBalance; //New customer's acccount balance (Can't be negative)
char lastPayment[DATE_SIZE]; //Date of the last payment
};
int main() {
splashScreen();
clearScreen();
CustomerAccount customer = { " ", " ", " ", " ", 0, " ", 0.0, " " };
std::string choice;
std::fstream record("CustomerAccount.dat", std::ios::in);
if (!record)
{
std::cout << "Could not find "CustomerAccount.dat". Creating the file.";
std::cout << " Press enter to continue the program. . .";
record.open("CustomerAccount.dat", std::ios::out);
std::getline(std::cin, choice);
}
record.close();
do
{
while (true)
{
clearScreen();
std::cout << " ---------------- Main Menu ----------------------";
std::cout << " | (E)nter a new record |";
std::cout << " | (A)dd payment to record |";
std::cout << " | (S)earch for a record |";
std::cout << " | (C)hange a record |";
std::cout << " | (R)emove a record |";
std::cout << " | (D)isplay contents of the file |";
std::cout << " | (Q)uit the program |";
std::cout << " ------------------------------------------------- ";
std::cout << " Choice: ";
std::getline(std::cin, choice);
if (choice.length() == 1)
{
choice[0] = toupper(choice[0]);
if (choice[0] == 'E' || choice[0] == 'A' || choice[0] == 'S' || choice[0] == 'C' ||
choice[0] == 'D' || choice[0] == 'R' || choice[0] == 'Q')
break;
}
std::cout << " Invalid input! Please re-enter your choice. Press enter to continue. . .";
std::getline(std::cin, choice);
}
switch (choice[0])
{
case 'E':
newRecord(customer);
break;
case 'A':
addPayment(customer);
break;
case 'S':
searchRecord(customer);
break;
case 'C':
changeRecord(customer);
break;
case 'R':
removeRecord(customer);
break;
case 'D':
displayContents(customer);
break;
default:
std::cout << " Thanks for using the program! ";
break;
}
} while (choice[0] != 'Q');
std::cout << " Press enter to exit the program. . .";
std::cin.get();
return 0;
}
void splashScreen() {
std::cout << " ";
std::cout << " ##### " << std::endl;
std::cout << " # # # # #### ##### #### # # ###### ##### " << std::endl;
std::cout << " # # # # # # # ## ## # # # " << std::endl;
std::cout << " # # # #### # # # # ## # ##### # # " << std::endl;
std::cout << " # # # # # # # # # # ##### " << std::endl;
std::cout << " # # # # # # # # # # # # # # " << std::endl;
std::cout << " ##### #### #### # #### # # ###### # # " << std::endl;
std::cout << " " << std::endl;
std::cout << " # " << std::endl;
std::cout << " # # #### #### #### # # # # ##### #### " << std::endl;
std::cout << " # # # # # # # # # # ## # # # " << std::endl;
std::cout << " # # # # # # # # # # # # #### " << std::endl;
std::cout << " ####### # # # # # # # # # # # " << std::endl;
std::cout << " # # # # # # # # # # # ## # # # " << std::endl;
std::cout << " # # #### #### #### #### # # # #### " << std::endl;
std::cout << " This program is desigend to create a customer account with the following info ";
std::cout << "Name, Address, City, state, ZIP, Telephone number, Account Balance, and Date of last payment.";
std::cout << " Press the enter key to continue.";
std::string line = "";
std::getline(std::cin, line);
}
void clearScreen() {
std::cout << std::string(100, ' ');
}
bool checkYN(std::string &userInput) {
if (userInput.length() == 1)
{
userInput[0] = toupper(userInput[0]);
if (userInput[0] == 'Y' || userInput[0] == 'N')
return true;
}
return false;
}
void searchRecord(CustomerAccount acc) {
clearScreen();
std::string tempString;
tempString = "";
long length = 0;
long recordNum = 0;
std::ifstream record("CustomerAccount.dat", std::ios::in | std::ios::binary);
if (!record)
{
std::cout << "Could not find "CustomerAccount.dat". Creating the file.";
std::cout << " Press enter to return to the main menu. . .";
record.open("CustomerAccount.dat", std::ios::out);
record.close();
std::getline(std::cin, tempString);
return;
}
record.seekg(0, std::ios::end);
length = record.tellg();
if (length == 0L)
{
std::cout << " There were no records found in the file." << std::endl;
std::cout << "Press enter to return to the main menu. . .";
std::getline(std::cin, tempString);
}
else
{
do
{
clearScreen();
while (true)
{
std::cout << " Enter the record number of the account you wish to search."
<< " Enter 'M' if you wish to return to the main menu. Record Number: ";
std::getline(std::cin, tempString);
if (tempString.length() == 1 && (tempString[0] == 'M' || tempString[0] == 'm'))
return;
std::stringstream myStream(tempString);
if (myStream >> recordNum && recordNum > 0)
break;
clearScreen();
std::cout << " Invalid record ID entered, please enter a valid record ID. ";
}
record.seekg(recordNum, std::ios::cur);
length = record.tellg();
record.clear();
if (length < 1)
std::cout << " Record not found. ";
else
{
recordNum--;
record.seekg(recordNum * sizeof(acc), std::ios::beg);
record.read(reinterpret_cast<char *>(&acc), sizeof(acc));
std::cout << " Record " << (recordNum + 1) << std::endl;
std::cout << " Name: " << acc.name << std::endl;
std::cout << "Address: " << acc.address << std::endl;
std::cout << "State: " << acc.state << std::endl;
std::cout << "City: " << acc.city << std::endl;
std::cout << "ZIP: " << acc.zip << std::endl;
std::cout << "Telephone: " << acc.telephone << std::endl;
std::cout << "Account Balance: $" << acc.accountBalance << std::endl;
std::cout << "Date of last payment: " << acc.lastPayment << std::endl;
std::cout << "------------------------------------------------------ ";
}
while (true)
{
std::cout << "Would you like to search for another record? (Y / N)";
std::cout << " Choice:";
std::getline(std::cin, tempString);
if (checkYN(tempString)) //checkYN checks if the string entered is either 'Y' or 'N'
break;
else
std::cout << "Invalid choice! Please re-enter your decision. ";
}
} while (tempString[0] == 'Y');
std::cout << " Press enter to return to the main menu. . . ";
std::getline(std::cin, tempString);
}
}
void displayContents(CustomerAccount acc) {
clearScreen();
std::ifstream displayFile("CustomerAccount.dat", std::ios::in | std::ios::binary);
std::string line = "";
if (!displayFile)
{
std::cout << "Could not find "CustomerAccount.dat". Creating the file.";
std::cout << " Press enter to return to the main menu. . .";
displayFile.open("CustomerAccount.dat", std::ios::out);
displayFile.close();
std::getline(std::cin, line);
return;
}
std::cout << "Contents of "CustomerAccount.dat" ";
displayFile.read(reinterpret_cast<char *>(&acc), sizeof(acc));
for (int count = 0; !displayFile.eof(); count++)
{
std::cout << " Record " << (count + 1) << std::endl;
std::cout << "Name: " << acc.name << std::endl;
std::cout << "Address: " << acc.address << std::endl;
std::cout << "State: " << acc.state << std::endl;
std::cout << "City: " << acc.city << std::endl;
std::cout << "ZIP: " << acc.zip << std::endl;
std::cout << "Telephone: " << acc.telephone << std::endl;
std::cout << "Account Balance: $" << acc.accountBalance << std::endl;
std::cout << "Date of last payment: " << acc.lastPayment << std::endl << std::endl;
displayFile.read(reinterpret_cast<char *>(&acc), sizeof(acc));
}
std::cout << "The entire document has been read.";
displayFile.close();
std::cout << " Press enter to return to the menu. . .";
std::getline(std::cin, line);
}
void newRecord(CustomerAccount acc) {
clearScreen();
std::string input = "";
std::cout << "Please have your information ready. ";
do
{
clearScreen();
userInput(acc, 0L);
while (true)
{
std::cout << " Would you like to enter another customer account? (Y / N) Choice: ";
std::getline(std::cin, input);
if (checkYN(input)) //checkYN checks if the string entered is either 'Y' or 'N'
break;
else
std::cout << "Invalid choice! Please re-enter your decision. ";
}
} while (input[0] == 'Y');
}
void addPayment(CustomerAccount acc) {
clearScreen();
std::string tempString, depositDate;
tempString = depositDate = "";
long length = 0;
long recordNum = 0;
double oldBalance, newBalance;
oldBalance = newBalance = 0.0;
Validation validate;
std::ifstream record("CustomerAccount.dat", std::ios::in | std::ios::out | std::ios::binary);
if (!record)
{
std::cout << "Could not find "CustomerAccount.dat". Creating the file.";
std::cout << " Press enter to return to the main menu. . .";
record.open("CustomerAccount.dat", std::ios::out);
record.close();
std::getline(std::cin, tempString);
return;
}
record.seekg(0, std::ios::end);
length = record.tellg();
if (length == 0L)
{
std::cout << " There were no records found in the file." << std::endl;
std::cout << "Press enter to return to the main menu. . .";
std::getline(std::cin, tempString);
}
else
{
record.close();
do
{
clearScreen();
std::fstream record("CustomerAccount.dat", std::ios::in | std::ios::out | std::ios::binary);
while (true)
{
std::cout << " Enter the record number of the account you wish to deposit to."
<< " Enter 'M' if you wish to return to the main menu. Record Number: ";
std::getline(std::cin, tempString);
if (tempString.length() == 1 && (tempString[0] == 'M' || tempString[0] == 'm'))
return;
std::stringstream myStream(tempString);
if (myStream >> recordNum && recordNum > 0)
break;
clearScreen();
std::cout << " Invalid record ID entered, please enter a valid record ID. ";
}
clearScreen();
record.seekg(recordNum, std::ios::cur);
length = record.tellg();
record.clear();
if (length < 1)
std::cout << " Record not found. ";
else
{
recordNum--;
record.seekg(recordNum * sizeof(acc), std::ios::beg);
record.read(reinterpret_cast<char *>(&acc), sizeof(acc));
std::cout << "Account: " << (recordNum + 1);
std::cout << " Name: " << acc.name << std::endl;
std::cout << "Account Balance: $" << acc.accountBalance << std::endl;
std::cout << "Date of last payment: " << acc.lastPayment << std::endl;
std::cout << "------------------------------------------------------ ";
oldBalance = acc.accountBalance;
AlterRecords checkDateOfDeposit(acc.lastPayment);
while (true)
{
std::cout << " Enter the deposit amount. ";
std::cout << "Deposit: ";
std::getline(std::cin, tempString);
if (tempString.length() == 0)
{
std::cout << " You didn't enter a valid balance! ";
continue;
}
std::stringstream myStream(tempString);
if (myStream >> acc.accountBalance && acc.accountBalance >= 0.0)
{
while (true)
{
std::cout << " You entered $" << std::showpoint << std::setprecision(2) << std::fixed << acc.accountBalance << " Is this correct? (Y/N) Choice: ";
std::getline(std::cin, tempString);
if (checkYN(tempString))
break;
else
std::cout << " Invalid choice! Please re-enter your decision. ";
}
if (tempString[0] == 'Y')
break;
}
else
{
std::cout << " You didn't enter a valid deposit amount! No negative values may be entered. ";
continue;
}
}
acc.accountBalance += oldBalance;
while (true)
{
std::cout << " Enter the date of this deposit. The format for the date is "MM/DD/YYYY" ";
std::cout << "Date: ";
std::getline(std::cin, depositDate);
if (!(validate.checkDate(depositDate)))
{
std::cout << " You didn't enter a valid date! ";
continue;
}
checkDateOfDeposit.setNewDate(depositDate);
tempString = checkDateOfDeposit.getNewestDate();
strcpy_s(acc.lastPayment, tempString.c_str());
while (true)
{
std::cout << " You entered " << depositDate << ". Is this correct? (Y/N) Choice: ";
std::getline(std::cin, tempString);
if (checkYN(tempString))
break;
else
std::cout << " Invalid choice! Please re-enter your decision. ";
}
if (tempString[0] == 'Y')
break;
}
record.seekp(recordNum * sizeof(acc), std::ios::beg);
record.write(reinterpret_cast<char *>(&acc), sizeof(acc));
record.close();
}
while (true)
{
std::cout << " Would you like to enter another deposit? (Y/N)";
std::cout << " Choice:";
std::getline(std::cin, tempString);
if (checkYN(tempString)) //checkYN checks if the string entered is either 'Y' or 'N'
break;
else
std::cout << "Invalid choice! Please re-enter your decision. ";
}
} while (tempString[0] == 'Y');
}
std::cout << " Press enter to return to the main menu. . . ";
std::getline(std::cin, tempString);
}
changeRecord allows the user to change the contents of a single record.
void changeRecord(CustomerAccount acc) {
clearScreen();
std::string tempString;
tempString = "";
long length = 0;
long recordNum = 0;
std::ifstream record("CustomerAccount.dat", std::ios::in | std::ios::binary);
if (!record)
{
std::cout << "Could not find "CustomerAccount.dat". Creating the file.";
std::cout << " Press enter to return to the main menu. . .";
record.open("CustomerAccount.dat", std::ios::out);
record.close();
std::getline(std::cin, tempString);
return;
}
record.seekg(0, std::ios::end);
length = record.tellg();
if (length == 0)
{
std::cout << " There were no records found in the file." << std::endl;
std::cout << "Press enter to return to the main menu. . .";
std::getline(std::cin, tempString);
}
else
{
do
{
clearScreen();
while (true)
{
std::cout << " Enter the record number of the account you wish to change."
<< " Enter 'M' if you wish to return to the main menu. Record Number: ";
std::getline(std::cin, tempString);
if (tempString.length() == 1 && (tempString[0] == 'M' || tempString[0] == 'm'))
return;
std::stringstream myStream(tempString);
if (myStream >> recordNum && recordNum > 0)
break;
clearScreen();
std::cout << " Invalid record ID entered, please enter a valid record ID. ";
}
record.seekg(recordNum, std::ios::cur);
length = record.tellg();
if (length == 0L)
std::cout << " Record not found.";
else
{
recordNum--;
record.seekg(recordNum * sizeof(acc), std::ios::beg);
record.read(reinterpret_cast<char *>(&acc), sizeof(acc));
std::cout << " This is the current record information.";
std::cout << " Record " << (recordNum + 1) << std::endl;
std::cout << " Name: " << acc.name << std::endl;
std::cout << "Address: " << acc.address << std::endl;
std::cout << "State: " << acc.state << std::endl;
std::cout << "City: " << acc.city << std::endl;
std::cout << "ZIP: " << acc.zip << std::endl;
std::cout << "Telephone: " << acc.telephone << std::endl;
std::cout << "Account Balance: $" << acc.accountBalance << std::endl;
std::cout << "Date of last payment: " << acc.lastPayment << std::endl;
std::cout << "------------------------------------------------------ ";
recordNum++;
record.close();
}
while (true)
{
std::cout << "Are you sure you would like to edit ? (Y / N)";
std::cout << " Choice:";
std::getline(std::cin, tempString);
if (checkYN(tempString)) //checkYN checks if the string entered is either 'Y' or 'N'
break;
else
std::cout << "Invalid choice! Please re-enter your decision. ";
}
if (tempString[0] == 'Y'){
userInput(acc, recordNum);
}
while (true)
{
std::cout << "Would you like to change another record? (Y / N)";
std::cout << " Choice:";
std::getline(std::cin, tempString);
if (checkYN(tempString)) //checkYN checks if the string entered is either 'Y' or 'N'
break;
else
std::cout << "Invalid choice! Please re-enter your decision. ";
}
} while (tempString[0] == 'Y');
std::cout << " Press enter to return to the main menu. . . ";
std::getline(std::cin, tempString);
}
}
void removeRecord(CustomerAccount acc) {
std::string tempString;
tempString = "";
long length = 0;
long recordNum = 0;
std::ifstream record("CustomerAccount.dat", std::ios::in | std::ios::binary);
if (!record)
{
std::cout << "Could not find "CustomerAccount.dat". Creating the file.";
std::cout << " Press enter to return to the main menu. . .";
record.open("CustomerAccount.dat", std::ios::out);
record.close();
std::getline(std::cin, tempString);
return;
}
record.seekg(0, std::ios::end);
length = record.tellg();
if (length == 0)
{
record.close();
std::cout << " There were no records found in the file." << std::endl;
std::cout << "Press enter to return to the main menu. . .";
std::getline(std::cin, tempString);
}
else
{
record.close();
do
{
std::ifstream record("CustomerAccount.dat", std::ios::in | std::ios::binary);
clearScreen();
while (true)
{
std::cout << " Enter the record number of the item you wish to remove."
<< " Enter 'M' if you wish to return to the main menu. Record Number: ";
std::getline(std::cin, tempString);
if (tempString.length() == 1 && (tempString[0] == 'M' || tempString[0] == 'm'))
return;
std::stringstream myStream(tempString);
if (myStream >> recordNum && recordNum > 0)
break;
clearScreen();
std::cout << " Invalid record ID entered, please enter a valid record ID. ";
}
record.seekg(recordNum, std::ios::cur);
length = record.tellg();
if (length == 0L)
std::cout << " Record not found.";
else
{
recordNum--;
record.seekg(recordNum * sizeof(acc), std::ios::beg);
record.read(reinterpret_cast<char *>(&acc), sizeof(acc));
std::cout << " This is the current record information.";
std::cout << " Record " << (recordNum + 1) << std::endl;
std::cout << " Name: " << acc.name << std::endl;
std::cout << "Address: " << acc.address << std::endl;
std::cout << "State: " << acc.state << std::endl;
std::cout << "City: " << acc.city << std::endl;
std::cout << "ZIP: " << acc.zip << std::endl;
std::cout << "Telephone: " << acc.telephone << std::endl;
std::cout << "Account Balance: $" << acc.accountBalance << std::endl;
std::cout << "Date of last payment: " << acc.lastPayment << std::endl;
std::cout << "------------------------------------------------------ ";
}
record.close();
while (true)
{
std::cout << "Are you sure you would like to remove this record? (Y / N)";
std::cout << " Choice:";
std::getline(std::cin, tempString);
if (checkYN(tempString)) //checkYN checks if the string entered is either 'Y' or 'N'
break;
else
std::cout << "Invalid choice! Please re-enter your decision. ";
}
if (tempString[0] == 'Y'){
CustomerAccount tempStruct;
std::fstream record("CustomerAccount.dat", std::ios::in | std::ios::binary);
std::fstream tempFile("tempFile.dat", std::ios::out | std::ios::binary);
if (record.fail() || tempFile.fail())
{
std::cout << " Error opening file. ";
return;
}
long count = 0L;
while (record.read((char*)&tempStruct, sizeof(tempStruct)))
{
if (!count == recordNum)
tempFile.write((char*)&tempStruct, sizeof(tempStruct));
count++;
}
std::cout << " Deletion Successful. ";
record.close();//We close the two files
tempFile.close();
remove("CustomerAccount.dat");
rename("tempFile.dat", "CustomerAccount.dat");
}
while (true) {
std::cout << "Would you like to remove another record? (Y / N)";
std::cout << " Choice:";
std::getline(std::cin, tempString);
if (checkYN(tempString)) //checkYN checks if the string entered is either 'Y' or 'N'
break;
else
std::cout << "Invalid choice! Please re-enter your decision. ";
}
} while (tempString[0] == 'Y');
std::cout << " Press enter to return to the main menu. . . ";
std::getline(std::cin, tempString);
}
}
void userInput(CustomerAccount acc, long recordNumChosen) {
std::fstream record("CustomerAccount.dat", std::ios::in | std::ios::out | std::ios::binary);
if (!recordNumChosen == 0L)
{
recordNumChosen--;
record.seekp(recordNumChosen * sizeof(acc), std::ios::beg);
}
record.seekp(0L, std::ios::end);
}
std::string input = "";
Validation validate;
while (true)//This loop gets the customer's name
{
std::cout << " Enter the customer's name. ";
std::cout << "Name: ";
std::getline(std::cin, input);
if (input.length() == 0 || input.length() >= NAME_SIZE)
{
std::cout << " You didn't enter a valid name! ";
continue;
}
strcpy_s(acc.name, input.c_str());//stores the string into the structure's name C-String
while (true)
{
std::cout << " You entered " << acc.name << ". Is this correct? (Y/N) Choice: ";
std::getline(std::cin, input);
if (checkYN(input)) //checkYN checks if the string entered is either 'Y' or 'N'
break;
else
std::cout << "Invalid choice! Please re-enter your decision. ";
}
if (input[0] == 'Y')
break;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.