Hi again. I was hoping I could find input from other members about the an assignment about classes. It goes as follows:
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
• memberID. 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 memberID data members. The constructor should also assign 0 to numBooks and purchaseAmt.
• Accessor. Appropriate accessor function to get the values stored in an object’s memberName, memberID, 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.
So here is my member.h file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#ifndef MEMBER_H
#define MEMBER_H
#include <string>
#include <iostream>
using namespace std;
// define the class members and member function prototypes here
class memberType
{
private:
string memberName;
string memberID;
int numBooks;
double purchaseAmt;
public:
//default constructor
memberType()
{
memberName = "";
memberID = "";
numBooks = 0;
purchaseAmt = 0;
}
public: void set(string Name, string ID, int Books, double Amt);
void modify(string Name);
void modify(int Books, double Amt);
void show();
};
void memberType::set(string Name, string ID, int Books, double Amt)
{
memberName = Name;
memberID = ID;
numBooks = Books;
purchaseAmt = Amt;
}
void memberType::modify(string Name)
{
memberName = Name;
}
void memberType::modify(int Books, double Amt)
{
numBooks = Books;
purchaseAmt = Amt;
}
void memberType::show()
{
cout << "Member's name is: " << memberName << endl;
cout << "Member's ID is: " << memberID << endl;
cout << "Number of books purhased are: " << numBooks << endl;
cout << "The amount of the purchase is: " << purchaseAmt << endl;
}
#endif
|
My member.ccp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <string>
#include <iostream>
#include "member.h"
using namespace std
// Write code for the following member functions:
//Constructor. The constructor should accept the person’s name and member identification number.***************
//*************These values should be assigned to the object’s memberName and memberID data members.***********
//*************The constructor should also assign 0 to numBooks and purchaseAmt.*******************************
memberType::memberType(string memberName, string memberID)
{
int numBooks = 0;
double purchaseAmt = 0;
cin >> memberName >> endl;
cin >> memberID >> endl;
}
//Accessor. Appropriate accessor functions to get the values stored in an object’s memberName,
//**********memberID, 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 as arguments. *****************************************
//****************The function should add these argument values to the existing numBooks and purchaseAmt data member.
|
and my client.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
// the current number of books and current purchase amount.
#include <iostream>
#include <string>
#include <iomanip>
#include "member.h"
using namespace std;
int main()
{
string Name, ID;
int Books;
double Amt;
memberType obj;
cout << "WELCOME TO PALOMA'S BOOK STORE" << endl;
cout << "ENTER LIBRARY MEMBER'S NAME: ";
cin >> Name;
cout << "ENTER LIBRARY MEMBER'S ID: ";
cin >> ID;
cout << "ENTER NUMBER OF BOOKS BOUGHT: ";
cin >> Books;
cout << "ENTER DOLLAR AMOUNT PER BOOK: ";
cin >> Amt;
obj.set(Name, ID, Books, Amt);
obj.show();
cout << "ENTER UPDATED NAME: ";
cin >> Name;
obj.modify(Name);
obj.show();
cout << "ENTER UPDATED BOOKS: ";
cin >> Books;
obj.modify(Books, Amt);
obj.show();
system("pause");
return 0;
} // end main
|
Unfortunately, I am not sure what to put into my member.ccp. I think maybe some of code from my .h file (granted it is correct) may be what needs to into member, but I would like some opinions.
Thank you. I appreciate all feedback.