I need some help with the following code. I want this to be the input data: This
ID: 3655556 • Letter: I
Question
I need some help with the following code.
I want this to be the input data:
This has to do with Classes and the Project is broken up into three files: Implementation, MainLine and Header File. If you have Bloodshed, this is what it's suppose to look like:
Here's my code:
Header File:
#ifndef MEMBERTYPE_H
#define MEMBERTYPE_H
#include<iostream>
#include<string>
using namespace std;
class memberType{
string memberID;
string firstName;
string lastName;
int booksPurchased;
double amountSpent;
public:
//prototype
memberType();
memberType(string ID, string fName, string lName,int bPurchased, double amount);
//mutators
void setMemberInfo(string ID, string fName, string lName,int bPurchased, double amount);
void setMemberID(string);
void setName(string, string);
//accessor
bool isMemberID(string) const;
int getBooksPurchased() const;
double getTotalAmountSpent() const;
//fxn, methods
void purchaseBook(double amount);
void resetbooksBoughtAndAmount();
void printMemberID() const;
void printName() const;
void printInfo() const;
};//end of class
#endif
Implementation File:
#include<iostream>
#include<string>
#include"memberType.h"
using namespace std;
memberType::memberType(){
memberID="0";
firstName="First";
lastName="Last";
booksPurchased=0;
amountSpent=0;
}
memberType::memberType(string ID, string fName, string lName,int bPurchased, double amount){
memberID=ID;
firstName=fName;
lastName=lName;
booksPurchased=bPurchased;
amountSpent=amount;
}
//mutators
void memberType::setMemberInfo(string ID, string fName, string lName,int bPurchased, double amount){
memberID=ID;
firstName=fName;
lastName=lName;
booksPurchased=bPurchased;
amountSpent=amount;
}
void memberType::setMemberID(string ID){memberID=ID;}
void memberType::setName(string fName, string lName){firstName=fName; lastName=lName;}
bool memberType::isMemberID(string ID) const{
return(memberID==ID); //returns 1 for true, 0 for false
}
//accessor
int memberType::getBooksPurchased() const{return booksPurchased;}
double memberType::getTotalAmountSpent() const{return amountSpent;}
//fxn, methods
void memberType::purchaseBook(double amount){
booksPurchased++;//add 1
amountSpent+=amount; //add amount to amountSpent
}
void memberType::resetbooksBoughtAndAmount(){//initializes booksPurchased and amountSpent to zero.
booksPurchased=0;
amountSpent=0;
}
void memberType::printMemberID() const{
cout<<memberID;
}
void memberType::printName() const{
cout<<firstName<<" "<<lastName;
return;
}
void memberType::printInfo() const{
cout<<" Member ID: ";
printMemberID();
cout<<" Name: ";
printName();
cout<<" Number of Books Bought: "<<booksPurchased;
cout<<" Total Amount Spent: $"<<amountSpent<<endl;
return;
}
Explanation / Answer
#ifndef MEMBERTYPE_H #define MEMBERTYPE_H #include #include using namespace std; class memberType{ string memberID; string firstName; string lastName; int booksPurchased; double amountSpent; public: //prototype memberType(); memberType(string ID, string fName, string lName,int bPurchased, double amount); //mutators void setMemberInfo(string ID, string fName, string lName,int bPurchased, double amount); void setMemberID(string); void setName(string, string); //accessor bool isMemberID(string) const; int getBooksPurchased() const; double getTotalAmountSpent() const; //fxn, methods void purchaseBook(double amount); void resetbooksBoughtAndAmount(); void printMemberID() const; void printName() const; void printInfo() const; };//end of class #endif #include #include #include"memberType.h" #include using namespace std; void getMembersData(memberType m[],int&); void printMembersData(memberType m[],int); int main(){ int count; memberType arr[500];//Declare an array of 500 memberType objects getMembersData(arr,count);//Invoke a function called getMembersData printMembersData(arr,count);//Invoke a function called printMembersData cin.get(); return 0; } void getMembersData(memberType m[],int &count){ string ID, fName, lName; int bookCount, i=0; double amount; ifstream infile;//Declare an input file infile.open("memberData.dat");//Open the file //infile>>count;//Read the member count from the first input record /* Use a while statement to : read the input record values for ID, fName, lName, bookCount and amount load the array of object variables invoking the setMemberInfo member */ count=0; while(!infile.eof()){ infile>>ID>>fName>>lName>>bookCount>>amount; m[count].setMemberInfo(ID, fName, lName, bookCount,amount); count++; } count--; infile.close(); return; } void printMembersData(memberType m[],int count){ /* Define printMembersData : Use a while statement to : Print the array of object variables invoking the printInfo member */ int i=0; while(iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.