This should be answere using C++ programming: Require 2 source files and one hea
ID: 3834239 • Letter: T
Question
This should be answere using C++ programming:
Require 2 source files and one header file with the names:
- member.h
- member.cpp
- clientProgram.cpp
In this exercise, you will design a class memberType. The class has the following data members: memberName A string that holds the name of a person member lD A string that holds the member identification number numBooks An int that holds the number of books bought purchaseAmt A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person's name and member identification number. These values should be assign to the object's memberName and memberlD data members. The constructor should also assign 0 to numBooks and purchaseAmt Accessor. Appropriate accessory function to get the values stored in an object's memberName, member lD, numBooks, and purchaseAmt data members. addNewPurchase. The addNewPurchase function should accept the number of books for a new purchase and the total amount of the purchase in dollars. The function should add these values to the existing numBooks and purchaseAmt data member. Demonstrate the class in a client program that creates a memberType object and then calls the addNewPurchase function twice (representing 2 new purchases). After each new purchase, display the member's id and name along with the current number of books and current purchase amount.Explanation / Answer
#include<iostream.h>
#include<string>
class memberType {
private:
string memberName;
string memberID;
int numBooks;
double purchaseAmt;
public:
memberType(string name, string id){
memberName = name;
memberID = id;
numBooks = 0;
purchaseAmt = 0;
}
string getMemberName(){
return memberName;
}
string getMemberID(){
return memberID;
}
int getNumBooks(){
return numBooks;
}
int getPurchaseAmt(){
return purchaseAmt;
}
void addNewPurchase(int num, int amt){
numBooks = numBooks + num;
purchaseAmt = purchaseAmt + amt;
}
};
void main(){
memberType mem("John", "1");
mem.addNewPurchase(3, 1000);
cout << mem.getMemberName() << " " << mem.getMemberID() << " " << mem.getNumBooks() << " ";
cout << "$" << mem.getPurchaseAmt() << endl;
mem.addNewPurchase(4, 2000);
cout << mem.getMemberName() << " " << mem.getMemberID() << " " << mem.getNumBooks() << " ";
cout << "$" << mem.getPurchaseAmt(); endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.