Question
Hello guys. Please help me with code. I tried to run them but I have three errors in loan.h. Please help and explain them to
Hello guys. Please help me with code. I tried to run them but I have three errors in loan.h. Please help and explain them to me. Please rely me asap when I will rate you!
Exercise.cpp
#include
using namespace std;
//global scopes void Prog13_1(); void Prog13_3(); void Prog13_13(); void Prog13_15(); void Prog13_17();
void Prog13_1() { //declare the object ofstream output; //the output object is used to open the text file //Use the ios::app mode to append the data //in random.txt if the file exists output.open("Exercise13_1.txt", ios::app); cout << "Create a text file: "; srand(time(0));
if (output.fail()) { cout << "File does not exist" << endl; cout << "Exit program." << endl; }
for (int i = 0; i < 100; i++) { //create 100 integers randomly int random_number = rand()%100; output << random_number << " "; } //close the file output.close();
//print the message cout << "Data appended" << endl; } // void Prog13_3() { //declare the object ifstream input; //declare the variables int sum = 0; double avg; //open a file input.open("Exercise13_3.txt"); cout << "Processing scores in a text file:"<< endl; if (input.fail()) { cout << "File does not exist" << endl; cout << "Exit program." << endl; } int scores, count = 0; while (!input.eof()) { input>>scores; //increment the count variables count++; sum += scores; } avg = (double) sum / count; input.close(); cout << " Sum of the scores: " << sum; cout << " Average of the scores: " << avg; }
void Prog13_13() { //create the object for binary input and output file ofstream binaryio("Exercise13_13.dat", ios::out|ios::binary | ios::app); srand(time(0));
if (binaryio.fail()) { cout << "File does not exist" << endl; cout << "Exit program." << endl; } for (int i = 0; i < 100; i++ ) { int random_number = rand()%100; binaryio.write((char*) &random_number, sizeof(int)); }
binaryio.close(); cout << "Data appended" << endl; }
void Prog13_15() { double sum = 0, i = 1; loan loanObj; //open file stream and read objects from file ifstream la; la.open("Exercise13_15.dat", ios::in | ios::binary); while (!la.eof()) { la.read(reinterpret_cast
void Prog13_17() { int count1, num, parts, partsize; double len; string filename, targetline, partnum; //prompt user to enter filename cout << "Enter the file name: "; cin>>filename; fstream biout, bin; bin.open(filename.c_str(), ios::in | ios::binary);
if (bin.fail()) { cout << "File doesnt not exist Exit program"; } //prompt user to enter part size cout << "Enter the number of bytes in each smaller file: "; cin >>partsize;
char* b = new char[partsize]; bin.read(b, partsize); bin.write(b, partsize); //check of existance of files bin.seekg(0,ios::end); len = bin.tellg(); bin.seekg(0, ios::beg); parts = len /partsize+1; //char b[partsize];
for (int i = 0; i < parts; i++) { targetline = filename; stringstream out; out<<" " << i; partnum = out.str(); targetline.append(partnum); bin.read(b, partsize); ifstream sf;
sf.open(targetline.c_str(), ios::out | ios::binary); //coping for (int j = 0; j < partsize; j++) { sf.putback(b[j]); sf.close(); //display each file cout << " File " << targetline << "produced "; } }
//close input file stream bin.close(); cout << " Split Done"; }
int main() { while (true) { system("cls"); cout << " Main Menu - Chapter 13" << endl; cout << "==============================" << endl; cout << " 1: Programming Exercise 13.1" << endl; cout << " 3: Programming Exercise 13.3" << endl; cout << " 13: Programming Exercise 13.13" << endl; cout << " 15: Programming Exercise 13.15" << endl; cout << " 17: Programming Exercise 13.17" << endl; cout << "other: Exit" << endl; cout << "==============================" << endl; cout << "Enter an exercise: "; char exercise[2]; cin >> exercise; cout << endl; switch (atoi(exercise)) { case 1: Prog13_1(); break; case 3: Prog13_3(); break; case 13: Prog13_13(); break; case 15: Prog13_15(); break; case 17: Prog13_17(); break; default: exit(0); } cout << endl; system("pause"); cin.clear(); } return 0; }
loan.h
#ifndef LOAN #define LOAN #include
class loan { public: //default constructor loan() { interestRatePerYear = 9.5; noOfYrs = 30; loanMoney = 100000; }
//constructor with arguments loan(double rate, int years, double amount) { interestRatePerYear = rate; none_ofYrs = years; loanMoney = amount; }
//accessor functions double getInterestRatePeryear() { return interestRatePerYear; }
int getNoOfyrs() { return NoOfYrs; }
double getLoanMoney() { return loanMoney; }
void setInterestRatePeryear(double rate) { interestRatePerYear = rate; }
void setNoOfYrs(int years) { noOfYrs = years; }
void setLoanMoney(double amount) { loanMoney = amount; }
double getMonthlyPayment() { double interestRateMonth = interestRatePerYear / 1200; return loanMoney * interestRatePerMonth /(1-(pow(1/(1+interestRatePerMonth), noOfYrs * 12))); } double getTotalPayment() { return noOfYrs * 12 * getMonthlyPayment(); }
private: double interestRatePerYear; int noOfYrs; double loanMoney;
}; #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started