Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a class memberType which its object can hold the name of a person, member

ID: 3780219 • Letter: D

Question

Define a class memberType which its object can hold the name of a person, member identification, number of books bought and amount spent. Include the member functions to perform the various operations on the objects of membertype - for example, modify, set, and show a person's name. Similarly, update, modify, and show the number of books bought and the amount spent. Add the appropriate constructors Write the definitions of the member functions of memberType. Write a program to test various operations of your class memberType.

Explanation / Answer

#include <iostream>
using namespace std;

class memberType
{
   private:
   string personName;
   string memberID;
   int booksBought;
   double amountSpent;
   public:
   memberType() //default constructor
   {
       this->personName = " ";
       this->memberID = " ";
       this->booksBought = 0;
       this->amountSpent = 0;  
   }
   memberType(string personName,string memberID,int booksBought,double amountSpent) //parameterized constructor
   {
       this->personName = personName;
       this->memberID = memberID;
       this->booksBought = booksBought;
       this->amountSpent = amountSpent;
      
   }
   void setPersonName(string personName) //set and get methods for all variables
   {
       this->personName = personName;
   }
   string getPersonName()
   {
       return personName;
   }
   void setMemberID(string memberId)
   {
       this->memberID = memberID;
   }
   string getMemberID()
   {
       return memberID;
   }
   void setBooksBought(int booksBought)
   {
       this->booksBought = booksBought;
   }
   int getBooksBought()
   {
       return booksBought;
   }
   void setAmountSpent(double amountSpent)
   {
       this->amountSpent = amountSpent;
   }
   double getAmountSpent()
   {
       return amountSpent;
   }
};
int main()
{
   memberType mt("John Smith","1000-455",4,234.50);
  
   //mt.setPersonName ="John Smith";
   //mt.setMemberID = "1000-455";
   //mt.setBooksBought = 4;
   //mt.setAmountSpent = 234.50;
  
   cout<<"Name :"<<mt.getPersonName();
   cout<<" Member Id :"<<mt.getMemberID();
   cout<<" Books bought :"<<mt.getBooksBought();
   cout<<" amount spent :"<<mt.getAmountSpent();
   return 0;
}

output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote