In your main you are only creating 1 single object (or instance) of the Presidents class, one object can only store 1 value in _number, _name, _quote and therefore displayPresidents() just wont work.
On the note of functions (forget its in the class for now), how would displayPresidents() know how many times to loop to show contents if you havent passed count to it? - you have assigned count inside the function to 0 and therefore it would never loop.
Anyway, I have tidied up your code a little and hopefully you will see what I mean.
#include<iostream>
#include<fstream>
#include<string>
usingnamespace std;
class Presidents
{
private:
int _number;
string _name;
string _quote;
public:
Presidents() { _number = 0; }
~Presidents() {}
// set the private variables
void setNumber(int number) { _number = number; }
void setName(string name) { _name = name; }
void setQuote(string quote) { _quote = quote; }
// return the private variables ( because they are private
// then outside of the class object they cant be seen or
// used so we need to create functions to pass them safely )
int getNumber() { return _number; }
string getName() { return _name; }
string getQuote() { return _quote; }
};
int main()
{
// we are assuming your storing 3 presidents,
// if its unknown at runtime you need to look
// at using vectors
// http://www.cplusplus.com/reference/vector/vector/
Presidents president[3];
int number;
string name;
string quote;
for (int i = 0; i < 3; i++)
{
cout << "Enter president no."<<i+1<<"'s number: ";
cin >> number;
cin.ignore();
cout << "\nEnter his name: ";
getline(cin, name);
cout << "\nEnter the his quote: ";
getline(cin, quote);
// Store in class object at index i
president[i].setNumber(number);
president[i].setName(name);
president[i].setQuote(quote);
}
// lets display the information in our three class objects.
for (int i = 0; i < 3; i++)
{
cout << "Name: " << president[i].getName() << ", No. " << president[i].getNumber() << ", Quote: " << president[i].getQuote() << endl;
}
return 0;
}
I know how to do the above, If i wanted to I could do that, but I cant combine presidents.h and presidents.cpp. I need to have all three of them separated like in the code i originally posted :(
The int getNumber string getName and string getQuote are supposed to be void functions, not value returning functions
They cant be void, you have declared private variables inside your class and unless its the actual object of the class accessing them then you cant see or use them inside your main, i.e. you need a way of returning those private variables back to whoever needs to use them.
// presidents.h
class Presidents
{
private:
int _number;
string _name;
string _quote;
public:
Presidents() { _number = 0; }
~Presidents() {}
// set the private variables
void setNumber(int number) { _number = number; }
void setName(string name) { _name = name; }
void setQuote(string quote) { _quote = quote; }
// return the private variables ( because they are private
// then outside of the class object they cant be seen or
// used so we need to create functions to pass them safely )
int getNumber() { return _number; }
string getName() { return _name; }
string getQuote() { return _quote; }
};
#include<iostream>
#include<fstream>
#include<string>
usingnamespace std;
#include "presidents.h" // header with class declaration
int main()
{
// we are assuming your storing 3 presidents,
// if its unknown at runtime you need to look
// at using vectors
// http://www.cplusplus.com/reference/vector/vector/
Presidents president[3];
int number;
string name;
string quote;
for (int i = 0; i < 3; i++)
{
cout << "Enter president no." << i + 1 << "'s number: ";
cin >> number;
cin.ignore();
cout << "\nEnter his name: ";
getline(cin, name);
cout << "\nEnter the his quote: ";
getline(cin, quote);
// Store in class object at index i
president[i].setNumber(number);
president[i].setName(name);
president[i].setQuote(quote);
}
// lets display the information in our three class objects.
for (int i = 0; i < 3; i++)
{
cout << "Name: " << president[i].getName() << ", No. " << president[i].getNumber() << ", Quote: " << president[i].getQuote() << endl;
}
return 0;
}
Failing that then I've not got a clue what you mean - if that's the case then I would suggest posting your actual assignment details.