//accessors
string get_containerType() const;
double get_diameter()const;
int get_numContainers()const;
void printrefund();
private://member variables
string m_containerType;//plastic or glass or aluminum
int m_numContainers;//how many containers
double m_diameter;//container size inches
if(size==5.0)
{
m_diameter=size;
cout<<" Machine has been set to container diameter of "<<m_diameter<<
" inches. "<<endl;
}
else if(size==3.0)
{
m_diameter=size;
cout<<" Machine has been set to container diameter of "<<m_diameter<<
" inches. "<<endl;
}
else if(size==2.0)
{
m_diameter=size;
cout<<" Machine has been set to container diameter of "<<m_diameter<<
" inches. "<<endl;
}
else if(size==0)
{
cout<<" Please manually enter the size of container. "<<endl;
}
else
{
cout<<" Machine cannot accept this size. "<<endl;
}
}
void RecyclingMachine::set_numContainers(int numbercont)
{
if(numbercont > 0)
{
m_numContainers=numbercont;
cout<<" You have inserted "<<m_numContainers<<" containers "<<endl;
}
else if(numbercont == 0)
{
cout<<" Please enter number of containers to be recycled. "<<endl;
}
}
void RecyclingMachine::printrefund()
{
get_numContainers();
get_diameter();
if(get_numContainers() > 0)
{
cout<<" Your deposit refund is "<<"$"<<get_numContainers()*.10<<endl;
}
else
cout<<" Please enter containers for deposit refund. "<<endl;
}
In your main function you haven't delcared any variables to accept the input. You've declared a object of type 'RecyclingMachine' but you haven't stated that your putting your values into that object e.g.
I created the variables in the main routine. But I dont think the main is calling the >> operator function. Am I supposed to somehow set mymachine1 equal to these variables, and then do cin>>mymachine1.
I think i might be on the wrong track . Thanks for the help
//Main Routine
#include <iostream>
#include "RecyclingMachine.h"
using namespace std;
#include <string>
using std::ostream;
using std::istream;
#include <iomanip>
int main()
{
RecyclingMachine mymachine1;//(string type, int howmany, double size)
//accessors
string get_containerType() const;
double get_diameter()const;
int get_numContainers()const;
void printrefund();
private://member variables
string m_containerType;//plastic or glass or aluminum
int m_numContainers;//how many containers
double m_diameter;//container size inches
if(size==5.0)
{
m_diameter=size;
cout<<" Machine has been set to container diameter of "<<m_diameter<<
" inches. "<<endl;
}
else if(size==3.0)
{
m_diameter=size;
cout<<" Machine has been set to container diameter of "<<m_diameter<<
" inches. "<<endl;
}
else if(size==2.0)
{
m_diameter=size;
cout<<" Machine has been set to container diameter of "<<m_diameter<<
" inches. "<<endl;
}
else if(size==0)
{
cout<<" Please manually enter the size of container. "<<endl;
}
else
{
cout<<" Machine cannot accept this size. "<<endl;
}
}
void RecyclingMachine::set_numContainers(int numbercont)
{
if(numbercont > 0)
{
m_numContainers=numbercont;
cout<<" You have inserted "<<m_numContainers<<" containers "<<endl;
}
else if(numbercont == 0)
{
cout<<" Please enter number of containers to be recycled. "<<endl;
}
}
void RecyclingMachine::printrefund()
{
get_numContainers();
get_diameter();
if(get_numContainers() > 0)
{
cout<<" Your deposit refund is "<<"$"<<get_numContainers()*.10<<endl;
}
else
cout<<" Please enter containers for deposit refund. "<<endl;
}
Oh right right, once you enter the variables you initialize my machine1 with them e.g.
mymachine1(contType, numCont, diameter);
This will initialize your object using the input you took, but this isn't what you want since you overloaded the operator>>, you want to be able to input a RecyclingMachine object or so I assume?
Also: please add the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
brace around your code, its killing my eyes.
Ok heres what I suppose you could do in main.
Ex 1:
[code]RecyclingMachine machina;
string name = "";
int nom = 0;
double dub = 0;
cin >> name >> nom >> dub;
machina(name,nom,dub);
cout << machina << endl;
Ex 2
1 2 3 4 5
RecyclingMachine machina;
cin >> machina; // This should work since you've overloaded the >>
cout << machina << endl;
Try these and tell me what happens. And you don't need to repost the entire code every single time, just what you've changed.