#include <string>
using namespace std;
class memberType
{
public:
void setMemberInfo(string ID, string firstName, string lastName,
int booksPurchasedRecently, double amountSpentRecently,
int booksPurchased, double amountSpent);
void printInfo();
bool isID(string ID);
string getID();
string getFirstName();
string getLastName();
int getBooksPurchasedRecently();
double getAmountSpentRecently();
int getBooksPurchased();
double getAmountSpent();
void purchaseBook(double amount);
void resetbooksPurchasedAndAmount();
private:
string ID;
string firstName;
string lastName;
int booksPurchasedRecently; // used for 11th book discount
double amountSpentRecently; // used for 11th book discount
int booksPurchased; // total number of books purchased (never be reset to 0)
double amountSpent; // total amount spent (this will never be reset to 0)
};
Using the .h file I'm supposed to access the classes and create a new program. I know everything Im supposed to do besides actually accessing the classes correctly. The instructor always gives us a pre-made lab and we are to finish it. That's easy. Starting from scratch is the hard part. Just a few hints would be great
Here's What I've Tried:
#include "bookType.h"
#include "memberType.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int N = 2000;
int main()
{
memberType list;
list.setMemberInfo();
list.printInfo();
{
ifstream infile;
string fname;
string x;
cout << "Enter file name: ";
cin >> fname;
infile.open(fname.c_str());
if(!infile){
cerr << "Error: Can't open data file." << endl;
return 1;
}
else{
while(!infile.eof){
infile >> x;
cout << x << endl;
infile >> x;
}
}
infile.close();
/*
bookType();
memberType();
ifstream infile;
string fname;
int index;
int n = 0;
string ntitle;
string title;
int x;
char c;
cout << "Enter file name: ";
cin >> fname;
infile.open(fname.c_str());
if(!infile){
cerr << "Error: Can't open data file." << endl;
return 1;
}
else{
while(!infile.eof){
infile >> x;
cout << x << endl;
infile >> x;
}
}
infile.close();
*/
return 0;
}}
The commented part is trying to see if I could get something out of the .dat file and it got one line so I know to tweak it a little to get all lines and store it to the array. Now my question is am I declaring it right by saying
memberType();Should it be
memberType.setMemberInfo();. Last question is how would I get the array to store strings and integers? I can get the integer but an error for the strings of the .dat file.
Thanks for any help

New Topic/Question
Reply



MultiQuote



|