Write in C++ using emacs.
Write a program that calculates the ending balance of several savings accounts. The program reads information about different customers’ accounts from an input file, “accounts.txt”. Each row in the file contains account information for one customer. This includes: the account number, account type (premium, choice, or basic account), starting balance, total amount deposited, and total amount withdrawn.
Your program should:
- open the file and check for successful open,
- then calculate the ending balance for each customer account. The calculated data must be saved in an output file, “accountsOut.txt”, in a neat format as shown below. You may assume that the interest is 5% for premium accounts, 3% for choice accounts, and 1% for basic accounts.
You MUST use a named constant for the interest rates. Since the results displayed are monetary values, your output must be displayed with two decimal places of precision. Be sure decimals “line up” when yu output the final accounts information. And do not forget to close the files when done with them.
Sample input file:
234019 Premium 50100.44 25500.00 14792.91
234490 Choice 35000.52 14000.00 15780.88
347269 Premium 80400.00 28750.00 15598.70
239801 Basic 5504.29 1700.00 1600.76
487241 Basic 4023.00 1950.00 1500.00
982111 Choice 9245.00 12300.00 11768.98
Sample output file:
Account Type StartBalance Deposit Withdrawal EndBalance
------------------------------------------------------------------------------------------------------------------
234019 Premium 50100.44 25500.00 14792.91 63847o.91
234490 Choice 35000.52 14000.00 15780.88 34216.23
347269 Premium 80400.00 28750.00 15598.70 98228.87
239801 Basic 5504.29 1700.00 1600.76 5659.56
487241 Basic 4023.00 1950.00 1500.00 4517.73
982111 Choice 9245.00 12300.00 11768.98 10069.30
Program 2
Modify program 1 to include a function getEndBalance that computes the ending balance of a savings account. The function takes three arguments that hold the starting balance, total deposits, total withdrawals and returns the ending balance. The ending balance is printed in main.
Program 3
Write a function minMaxAvg that calculates and returns the min im um, maximum , and average of three integers . Then write a main program to test your function.
You r main program should:
- ask the user to enter three integers,
- calls the function minMaxAvg to compute the minimum, maximum and average of the three entered integer values , - print the minimum, maximum, and average (minimum, maximum, average need to be sen t by reference).
Sample run :
Please enter 3 numbers: 100 80 92
The average is: 90.66
The min is: 80
The max is: 100
//program 1
#include<iostream>
#include<fstream>
#include<string>
//include iomanip for formatted output
#include<iomanip>
#define MAX 500
using namespace std;
int main()
{
double start_bal, deposit, withdrawal,balance;
int acc_id;
string acc_type;
//ifstream object to read from file
ifstream in;
in.open("accounts.txt");
//check if file is open
if (!in)
{
cout << "Not able to open
file" << endl;
return -1;
}
//open file for writing
ofstream out;
out.open("accountsOut.txt");
//check fi output file can be opened for writing
if (!out)
{
cout << "Not able to open
file for writing" << endl;
return -1;
}
int count = 0;
cout << fixed << setprecision(2);
out << fixed << setprecision(2);
//cout << "Account
Type\tStartBalance\tDeposit\tWithdral EndBalance\n" <<
endl;
out << "Account
Type\tStartBalance\tDeposit\tWithdral EndBalance\n" <<
endl;
while (!in.eof())
{
in >> acc_id >>
acc_type >> start_bal >> deposit >>
withdrawal;
balance = start_bal + deposit -
withdrawal;
//output all values to file
balance = (start_bal + deposit -
withdrawal);
if(acc_type == "Premium")
out <<
setw(6) << left << acc_id << "\t" <<
setw(8) << left << acc_type << setw(12) <<
left << start_bal << setw(12) << left <<
deposit << setw(12) << left << withdrawal
<< setw(12) << left << balance+(balance * 5) /
100 << endl;
else if(acc_type == "Choice")
out <<
setw(6) << left << acc_id << "\t" <<
setw(8) << left << acc_type << setw(12) <<
left << start_bal << setw(12) << left <<
deposit << setw(12) << left << withdrawal
<< setw(12) << left << balance + (balance * 3) /
100 << endl;
else
out <<
setw(6) << left << acc_id << "\t" <<
setw(8) << left << acc_type << setw(12) <<
left << start_bal << setw(12) << left <<
deposit << setw(12) << left << withdrawal
<< setw(12) << left << balance + (balance * 1) /
100 << endl;
//cout << setw(6) <<
left << acc_id << "\t"<<setw(8) << left
<< acc_type << setw(12) << left <<start_bal
<< setw(12) << left <<deposit << setw(12)
<<left << withdrawal << setw(12) << left
<<(start_bal + deposit - withdrawal) << endl;
++count;
}
}
========================
//input file name accounts.txt
234019 Premium 50100.44 25500.00 14792.91
234490 Choice 35000.52 14000.00 15780.88
347269 Premium 80400.00 28750.00 15598.70
239801 Basic 5504.29 1700.00 1600.76
487241 Basic 4023.00 1950.00 1500.00
982111 Choice 9245.00 12300.00 11768.98
//Check accountsOut.txt file for output
Account Type StartBalance Deposit Withdral EndBalance
234019 Premium 50100.44 25500.00 14792.91
63847.91
234490 Choice 35000.52 14000.00 15780.88 34216.23
347269 Premium 80400.00 28750.00 15598.70
98228.87
239801 Basic 5504.29 1700.00 1600.76 5659.57
487241 Basic 4023.00 1950.00 1500.00 4517.73
982111 Choice 9245.00 12300.00 11768.98 10069.30
===================================
//Program 2 and program 3 in program 1
#include<iostream>
#include<fstream>
#include<string>
//include iomanip for formatted output
#include<iomanip>
#define MAX 500
using namespace std;
//declare function for program2
double getEndBalance(double bal, double deposits, double
withdrawal);
//declare function for program 3
void minMaxAvg(double &avg);
int main()
{
double start_bal, deposit, withdrawal,balance;
int acc_id;
string acc_type;
//ifstream object to read from file
ifstream in;
in.open("accounts.txt");
//check if file is open
if (!in)
{
cout << "Not able to open
file" << endl;
return -1;
}
//open file for writing
ofstream out;
out.open("accountsOut.txt");
//check fi output file can be opened for writing
if (!out)
{
cout << "Not able to open
file for writing" << endl;
return -1;
}
int count = 0;
cout << fixed << setprecision(2);
out << fixed << setprecision(2);
//cout << "Account
Type\tStartBalance\tDeposit\tWithdral EndBalance\n" <<
endl;
out << "Account
Type\tStartBalance\tDeposit\tWithdral EndBalance\n" <<
endl;
while (!in.eof())
{
in >> acc_id >>
acc_type >> start_bal >> deposit >>
withdrawal;
balance = start_bal + deposit -
withdrawal;
//output all values to file
balance = (start_bal + deposit -
withdrawal);
if (acc_type == "Premium")
{
balance =
getEndBalance(start_bal, deposit, withdrawal);
cout <<
"Ending balance: " << balance + (balance * 5) / 100 <<
endl;
out <<
setw(6) << left << acc_id << "\t" <<
setw(8) << left << acc_type << setw(12) <<
left << start_bal << setw(12) << left <<
deposit << setw(12) << left << withdrawal
<< setw(12) << left << balance + (balance * 5) /
100 << endl;
}
else if (acc_type ==
"Choice")
{
balance =
getEndBalance(start_bal, deposit, withdrawal);
cout <<
"Ending balance: " << balance + (balance * 3) / 100 <<
endl;
out <<
setw(6) << left << acc_id << "\t" <<
setw(8) << left << acc_type << setw(12) <<
left << start_bal << setw(12) << left <<
deposit << setw(12) << left << withdrawal
<< setw(12) << left << balance + (balance * 3) /
100 << endl;
}
else
{
out <<
setw(6) << left << acc_id << "\t" <<
setw(8) << left << acc_type << setw(12) <<
left << start_bal << setw(12) << left <<
deposit << setw(12) << left << withdrawal
<< setw(12) << left << balance + (balance * 1) /
100 << endl;
balance =
getEndBalance(start_bal, deposit, withdrawal);
cout <<
"Ending balance: " << balance + (balance * 1) / 100 <<
endl;
}
//cout << setw(6) <<
left << acc_id << "\t"<<setw(8) << left
<< acc_type << setw(12) << left <<start_bal
<< setw(12) << left <<deposit << setw(12)
<<left << withdrawal << setw(12) << left
<<(start_bal + deposit - withdrawal) << endl;
++count;
}
//call to test minMaxAvg for program 3
double avg;
minMaxAvg(avg);
}
double getEndBalance(double bal, double deposits, double
withdrawal)
{
return (bal + deposits - withdrawal);
}
void minMaxAvg(double &avg)
{
int one, two, three;
cout << "Enter three numbers: ";
cin >> one >> two >> three;
avg = (one + two + three) / 3.00;
cout << "The average is : " <<
avg<<endl;
if (one >= two && one >= three)
cout << "The max is "
<< one << endl;
if (two >= one && two >= three)
cout << "The max is "
<< two << endl;
if (three >= one && three >=
two)
cout << "The max is "
<< three << endl;
if (one <= two && one <= three)
cout << "The min is "
<< one << endl;
if (two <= one && two <= three)
cout << "The min is "
<< two << endl;
if (three <= one && three <=
two)
cout << "The min is "
<< three << endl;
}
==============================
//output for program2 and program3 called in program 1
Ending balance: 63847.91
Ending balance: 34216.23
Ending balance: 98228.87
Ending balance: 5659.57
Ending balance: 4517.73
Ending balance: 10069.30
Enter three numbers: 100 80 92
The average is : 90.67
The max is 100
The min is 80
Write in C++ using emacs. Write a program that calculates the ending balance of several savings...
C++ 18. Savings Account Balance Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following A) Ask the user for the total amount deposited into the account during that month. Do not accept negative numbers. This amount should be added to the...
C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...
Write in C Program.... Write a multi-threaded program that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create three separate worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, and the third will determine the minimum value. For example, suppose your program is passed the integers 90 81 78 95 79 72 85. The...
i need this to be in OOP using C++ 25. Savings Account Balance Write a program that calculates the balance of a savings account at the end of a three-month feried. It should ask the user for the starting balance and the annual interest rate. A loop abculd then iterate once for every month in the period, performing the following steps: B) A) Ask the user for the total amount deposited into the account during that month and add it...
In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; } while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...
with explanation Write a C++ program that calculates and prints the average of several integers. Assume that the last value read with cin >> is the number 9999. For example, for an input sequence: 10 8 11 7 9 9999 The output should be 9.00
Project DescriptionWrite a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".Project SpecificationsInput for this project:the user must enter the number of employees in the company.the user must enter as integers for each employee:the employee number (ID)the number of days that employee missed during the past year.Input Validation:Do not accept a number less than 1 for the number of employees.Do not accept a negative...
Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...
Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...
Write a program that calculates the amount of money that you must invest In a savings account at a given interest rate for a given number of years to have a certain dollar amount at me end of the period Y our program will ask the user for the amount the user wants to have at the end of the term (future value). the number of years the user plans to let the money stay in the account, and the...