Hello everyone!
I know not a lot of C++ coding goes on here, but I was wondering if anyone knows enough to help me with a school assignment. There were very few directions, and I need help writing an accessor function and getting class methods to access a ifstream text file.
#include <iostream>
#include <string>
#include <fstream>
#include "memberType.h"
using namespace std;
// This program displays the member's name the member's id and the total amount of the purchase and books.
void getMembersData(memberType members[], int& count);
void printMembersData(memberType members[], int count);
int main()
{
memberType storeMembers[500];
int numberOfMembers = 0;
memberType test;
test.printMemberID();
test.printName();
cout << endl;
test.printInfo();
getMembersData(storeMembers, numberOfMembers);
printMembersData(storeMembers, numberOfMembers);
return 0;
}
void getMembersData(memberType members[], int& count)
{
int i;
string ID;
string fName;
string lName;
int bookCount;
double amount;
ifstream infile;
infile.open("memberData.txt");
infile >> count;
for (i = 0; i < count; i++)
{
infile >> ID >> fName >> lName >> bookCount >> amount;
members[i].setMemberInfo(ID, fName, lName, bookCount, amount);
}
}
void printMembersData(memberType members[], int count)
{
int i;
for (i = 0; i < count; i++)
members[i].printInfo();
}
//implementation file
#include <iostream>
#include <string>
#include<fstream>
#include "memberType.h"
using namespace std;
void memberType::setMemberInfo(string ID, string fName,string lName, int bPurchased,double amount)
{
int i;
int count;
ifstream infile;
infile.open("memberData.txt");
infile >> count;
for (i = 0; i < count; i++)
{
infile >> ID >> fName >> lName >> bPurchased >> amount;
memberID = ID;
firstName = fName;
lastName = lName;
numBooks = 0;
purchaseAmt = 0;
}
//get member data from input file.....this needs to set the memberType object
//Accessor Function for homework
}
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);
}
int memberType::getBooksPurchased() const
{
return numBooks;
}
double memberType::getTotalAmountSpent() const
{
return purchaseAmt;
}
void memberType::addNewPurchase(double amount)
{
numBooks = amount + numBooks;
purchaseAmt = amount + purchaseAmt;
// This is be the addNewPurchase that wil accept the number of books
// and the total amount in dollars
// This method needs to add these values to the numBooks and
}
void memberType::resetbooksBoughtAndAmount()
{
numBooks = 0;
purchaseAmt = 0;
}
void memberType::printMemberID() const
{
cout << "Member ID: " << memberID << endl;
}
void memberType::printName() const
{
cout << "Name: " << firstName << " " << lastName << endl;
}
void memberType::printInfo() const
{
cout << "Member ID: " << memberID << endl;
cout << "Name: " << firstName << " " << lastName << endl;
cout << "Number of Books Bought: " << numBooks << endl;
cout << "Total Amount Spent: " << purchaseAmt << endl;
}
memberType::memberType(string ID, string fName,string lName)
{
memberID = ID;
firstName = fName;
lastName = lName;
numBooks = 0;
purchaseAmt = 0;
//This is the contructor part of the homework
//Make sure it is ready to accept values from the input file
}
memberType::memberType(){
}
//header file
#pragma once
#pragma once
#include <string>
using namespace std;
class memberType
{
public:
void setMemberInfo(string ID, string fName, string lName,
int bPurchased, double amount);
void setMemberID(string);
void setName(string, string);
bool isMemberID(string) const;
int getBooksPurchased() const;
double getTotalAmountSpent() const;
void addNewPurchase(double amount);
void resetbooksBoughtAndAmount();
void printMemberID() const;
void printName() const;
void printInfo() const;
void getMembersData(memberType members[], int& count);
memberType();
memberType(string ID, string fName,string lName);
private:
string memberID;
string firstName;
string lastName;
int numBooks;
double purchaseAmt;
};
//text file
0
10
John Williams
0
0
20
Lisa Berry
2
35.50
30
Ron Brown
10
255.68
40
Jessey Smith
0
0
I know it is long but anything would be helpful.