Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #include #include #include #include #include "loan.h"

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(&loanObj), sizeof(loanObj)); cout << "The total payment of " << i++ << " loan amount is " << loanObj.getTotalPayment() << endl; sum += loanObj.getTotalPayment(); } //closing the file stream la.close(); //display the sum of all loans cout << "The total amount of all loans is" << sum << endl; }

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 #include using namespace std;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

1.what is the significance of Taxonomy ?

Answered: 1 week ago

Question

What are the advantages and disadvantages of leasing ?

Answered: 1 week ago

Question

Name is needed for identifying organisms ?

Answered: 1 week ago

Question

LO4 Provide an overview of four challenges facing HR today.

Answered: 1 week ago