Define a class memberType which its object can hold the name of a person, member
ID: 3581691 • 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
Please find below the C++ programs with comments to help you understand better:
#include<iostream>
#include<string>
using namespace std;
class memberType //class declared
{
public: string Name; //string name
string ID;
int no_books; //no_books as integers type
float amount; //amount as float type
memberType()
{
Name=" ";
ID=" ";
no_books=0;
amount=0.00;
}
public: void set(string name, string id, int no, float a); //Declaration part
void modify(string name); //to modify name
void modify(int no, float a);
void show();
};
void memberType::set(string n, string id, int no, float a)
{
Name=n;
ID=id;
no_books=no;
amount=a;
}
void memberType::modify(string name) //membertype name
{
Name=name;
}
void memberType::modify(int no, float a) //to modify no. and a
{
no_books=no;
amount=a;
}
void memberType::show()
{
cout<<"Person's Name is: "<<Name<<endl; //print section for person name
cout<<"Person's ID is: "<<ID<<endl; //print section for person ID
cout<<"Number of Books is: "<<no_books<<endl; //print section for No. of books
cout<<"Amount Spent is: "<<amount<<endl; //print section for Amt. Spent
}
-------------------------------------------------------------------------
#include<iostream>
#include<string>
using namespace std;
int main() //main() function
{
string n,id;
int books; //books as int type
float a; //a as float type
memberType obj;
cout<<"WELCOME TO ERIK's BOOK STORE"<<endl;
cout<<"PLEASE ENTER LIBRARY MEMBER'S NAME: "; //ENTER THE LIBRARY MEMBER'S NAME
cin>>n;
cout<<"PLEASE ENTER LIBRARY MEMBER'S ID: "; //ENTER HERE LIBRARY MEMBER'S ID
cin>>id;
cout<<"PLEASE ENTER NUMBER OF BOOKS BOUGHT: "; //ENTER THE NO. OF BOOKS BOUGHT
cin>>books;
cout<<"PLEASE ENTER DOLLAR AMOUNT PER BOOK: "; //ENTER HERE DOLLAR AMT. PER BOOK
cin>>a;
obj.set(n, id, books, a);
obj.show();
cout<<"PLEASE ENTER UPDATED NAME: "; //update the name here, if in case is needed
cin>>n;
obj.modify(n);
obj.show();
cout<<"PLEASE ENTER UPDATED BOOKS: ";
cin>>books;
obj.modify(books, a); //if modify is needed
obj.show();
system("pause"); //pause
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.