This program will record the information you give it to a text file called 'Financial.txt'. the program is pretty easy to understand, and if you are using Code::Blocks, start a new console c++ application and paste the following code into it:
- Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
//variables
int SecurityCode = 3131997;
int Securityinput;
int timesAttempted;
int TimeWaitRemaining;
//function declarations
int NewFileWrite();
int NewFileInput();
int TMIA();
int SecureInput();
int PreFileInput();
//all class functions
int JobEstablishmentFileUpdate();//unfinished
int JobDescriptionFileUpdate();//unfinished
int FirstNameFileUpdate();//unfinished
int LastNameFileUpdate();//unfinished
int AmountCashFileUpdate();//unfinised
int AmountCreditFileUpdate();//unfinished
int AmountDueFileUpdate();//unfinished
int WeeklyWagesFileUpdate();//unfinished
int HoursWeeklyFileUpdate();//unfinished
int OvertimeWagesFileUpdate();//unfinished
int OvertimeHoursFileUpdate();//unfinished
int TaxReductionFileUpdate();//unfinished
//classes
class EmployeeRichard
{
public:
char jobEstablishment[128];
char jobDescription[128];
char firstName[128];
char lastName[128];
char amountCash[128];
char amountCredit[128];
char amountDue[128];
char weeklyWages[128];
char hoursWorked[128];
char overtimeWages[128];
char overtimeHours[128];
char taxReduction[128];
};
EmployeeRichard er;
int main()
{
SecureInput();
return 0;
}
int NewFileWrite()
{
ofstream myfile ("Financial.txt");
if (myfile.is_open())
{
myfile << er.jobEstablishment;
myfile << er.jobDescription;
myfile << er.firstName;
myfile << er.lastName;
myfile << er.amountCash;
myfile << er.amountCredit;
myfile << er.amountDue;
myfile << er.weeklyWages;
myfile << er.hoursWorked;
myfile << er.overtimeWages;
myfile << er.overtimeHours;
myfile << er.taxReduction;
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
int SecureInput()
{
cout << "enter in the security code to proceed, you have 3 tries ";
cin >> Securityinput;
if(Securityinput != SecurityCode)
{
if(timesAttempted >= 2)
{
TimeWaitRemaining = 10000;
cout << "you have exceeded the required number of attempts, you must now wait until the number reaches 0" << endl;
TMIA();
}
else
{
cout << "wrong code, you have reduced your amount of tries remaining." << endl;
timesAttempted ++;
SecureInput();
}
}
else
{
cout << "code is correct, you may continue." << endl;
PreFileInput();
}
return 0;
}
int TMIA()
{
if(TimeWaitRemaining <= 0)
{
main();
}
else
{
cout << TimeWaitRemaining << endl;
TimeWaitRemaining --;
TMIA();
}
return 0;
}
int PreFileInput()
{
int x;
cout << "Have you entered any information before? 1= yes, 2=no" << endl;
cin >> x;
if(x == 1)
{
int y;
cout << "what would you like to edit in the file? 1=jobestablishment 2=jobdescription 3=firstname 4=lastname 5=amountcash 6=amountcredit 7=amountdue 8=weeklywages 9=hoursworked 10=overtimewages 11=overtimehours 12=taxreduction 13=Exit" << endl;
cin >> y;
if(y == 1)
{
JobEstablishmentFileUpdate();
}
else
if(y == 2)
{
JobDescriptionFileUpdate();
}
else
if(y == 3)
{
FirstNameFileUpdate();
}
else
if(y == 4)
{
LastNameFileUpdate();
}
else
if(y == 5)
{
AmountCashFileUpdate();
}
else
if(y == 6)
{
AmountCreditFileUpdate();
}
else
if(y == 7)
{
AmountDueFileUpdate();
}
else
if(y == 8)
{
WeeklyWagesFileUpdate();
}
else
if(y == 9)
{
HoursWeeklyFileUpdate();
}
else
if(y == 10)
{
OvertimeWagesFileUpdate();
}
else
if(y == 11)
{
OvertimeHoursFileUpdate();
}
else
if(y == 12)
{
TaxReductionFileUpdate();
}
else
if(y == 13)
{
main();
}
}
else
{
NewFileInput();
}
return 0;
}
int NewFileInput()
{
cout << "hello new user, welcome to the M.M.C.A." << endl;
cout << "where do you work?" ;
cin >> er.jobEstablishment;
cout << "what do you do? " ;
cin >> er.jobDescription;
cout << "what is your first name?" ;
cin >> er.firstName;
cout << "what is your last name?" ;
cin >> er.lastName;
cout << "how much money do you have in cash?" ;
cin >> er.amountCash;
cout << "how much money do you have on a debit card?";
cin >> er.amountCredit;
cout << "how much money do you owe, if applicable?";
cin >> er.amountDue;
cout << "how much do you earn in an hour" ;
cin >> er.weeklyWages;
cout << "how many hours do you put in a week?" ;
cin >> er.hoursWorked;
cout << "how much do you earn an hour on overtime?" ;
cin >> er.overtimeWages;
cout << "how many overtime hours do you put in weekly?";
cin >> er.overtimeHours;
cout << "how much of your pay goes to taxes, if applicable?";
cin >> er.taxReduction;
NewFileWrite();
return 0;
}
int JobDescriptionFileUpdate()
{
cout << "What is your new job description?";
cin >> er.jobDescription;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.jobDescription;
myfile.close();
}
PreFileInput();
return 0;
}
int JobEstablishmentFileUpdate()
{
cout << "Where do you now work?";
cin >> er.jobEstablishment;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.jobEstablishment;
myfile.close();
}
PreFileInput();
return 0;
}
int FirstNameFileUpdate()
{
cout << "what is your First name?";
cin >> er.firstName;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.firstName;
myfile.close();
}
PreFileInput();
return 0;
}
int LastNameFileUpdate()
{
cout << "what is your last name?" ;
cin >> er.lastName;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.lastName;
myfile.close();
}
PreFileInput();
return 0;
}
int AmountCashFileUpdate()
{
cout << "what is your new amount of cash?" ;
cin >> er.amountCash;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.amountCash;
myfile.close();
}
PreFileInput();
return 0;
}
int AmountCreditFileUpdate()
{
cout << "How much credit do you now have?" ;
cin >> er.amountCredit;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.amountCredit;
myfile.close();
}
PreFileInput();
return 0;
}
int AmountDueFileUpdate()
{
cout << "How much do you now owe?";
cin >> er.amountDue;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.amountDue;
myfile.close();
}
PreFileInput();
return 0;
}
int WeeklyWagesFileUpdate()
{
cout << "How much do you now make per hour?";
cin >> er.weeklyWages;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.weeklyWages;
myfile.close();
}
PreFileInput();
return 0;
}
int HoursWeeklyFileUpdate()
{
cout << "How many hours do you work a week?";
cin >> er.hoursWorked;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.hoursWorked;
myfile.close();
}
PreFileInput();
return 0;
}
int OvertimeWagesFileUpdate()
{
cout << "How much do you get when you work overtime?";
cin >> er.overtimeWages;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.overtimeWages;
myfile.close();
}
PreFileInput();
return 0;
}
int OvertimeHoursFileUpdate()
{
cout << "How many hours have you worked overtime this week?";
cin >> er.overtimeHours;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.overtimeHours;
myfile.close();
}
PreFileInput();
return 0;
}
int TaxReductionFileUpdate()
{
cout << "What percent of your paycheck is reduced because of taxes?";
cin >> er.taxReduction;
ofstream myfile ("Financial.txt");
if(myfile.is_open())
{
myfile << er.taxReduction;
myfile.close();
}
PreFileInput();
return 0;
}