Question: DESCRIPTION In this assignment, you are asked to define a class named Loan. This class represents loans taken from a bank. There are five basic
DESCRIPTION In this assignment, you are asked to define a class named Loan. This class represents loans taken from a bank. There are five basic pieces of information each loan must have: the name of the bank giving out the loan (string), the name of the borrower (string), the annual interest rate (double), the number of years (integer), and finally the loan amount (double). Model this class after the Course class below and define it in a loan.h file under the /include folder. At a minimum, you must have:
four constructors
a destructor an accessor and a mutator for each attribute.
a str() function that summarizes the loan and all of its information.
Your class can have more data and function members of your choosing. In main.cpp file under the src/ folder, create eight different loan objects with different made-up names and amounts as follows:
Four objects are defined statically in the stack. Use a different constructor for each object. Call the needed mutator functions to provide these objects with the information that the constructors did not provide.
Four objects are defined dynamically in the heap. Use a different constructor for each object. Call the needed mutator functions to provide these objects with the information that the constructors did not provide.
These objects should then be inserted into a C++-style array or a vector and printed out in the same manner as the sample main function below.
Here is the course.h file that defines the Course class:
#ifndef _COURSE_H_ #define _COURSE_H_
#include
/* * A class representing courses */ class Course { private: std::string crn; // CS1410 std::string name; // Object-oriented Programming int creditHours; // 4 int year; // 2020 std::string semester; // Summer
public: // Constructors Course() : crn(""), name(""), creditHours(0), year(0), semester("") {} Course(std::string c, std::string n) : crn(c), name(n), creditHours(0), year(0), semester("") {} Course(std::string c, std::string n, int ch, int y, std::string s) : crn(c), name(n), creditHours(ch), year(y), semester(s) {}
// Destructor ~Course() {}
// Accessors and mutators // CRN const std::string& getCrn() const { return crn; } void setCrn(const std::string& c) { crn = c; }
// Name const std::string& getName() const { return name; } void setName(const std::string& n) { name = n; }
// Credit hours int getCreditHours() const { return creditHours; } void setCreditHours(int ch){ creditHours = ch; }
// Year int getYear() const { return year; } void setYear(int y) { year = y; }
// Semester const std::string& getSemester() const { return semester; } void setSemester(const std::string& s) { semester = s; }
// Prints course info std::string str() const { std::stringstream sout; sout << " CRN: " << crn << std::endl << " NAME: " << name << std::endl << "CREDIT HOURS: " << creditHours << std::endl << " YEAR: " << year << std::endl << " SEMESTER: " << semester << std::endl; return sout.str(); } };
# endif
And here is the main.cpp with a main function for testing the Course class above:////////////////////////////////////////////////////////////////////////////
#include "course.h" #include
int main() { // Create three objects statically (in the stack) Course a; a.setCrn("CS1410"); a.setName("Object-oriented Programming"); a.setCreditHours(4); a.setYear(2020); a.setSemester("Summer");
Course b("CS1400", "Programming I"); b.setCreditHours(4); b.setYear(2020); b.setSemester("Spring");
Course c("CS2420", "Data Structures", 4, 2020, "Summer");
// Create three objects dynamically (in the heap) Course *c1 = new Course; c1->setCrn("CS1030"); c1->setName("Introduction to CS"); c1->setCreditHours(4); c1->setYear(2020); c1->setSemester("Fall");
Course *c2 = new Course("CS2350", "Client-side Web Development"); c2->setCreditHours(4); c2->setYear(2020); c2->setSemester("Spring");
Course *c3 = new Course("CS3100", "Operating Systems", 4, 2020, "Summer");
// Print all courses vector
delete c1; delete c2; delete c3;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
