Tally machine program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hypnotik
    New Member
    • Jun 2007
    • 87

    #1

    Tally machine program

    Well on to my next program. The program tally's votes on 3 issues. I have a class for the interface (asks questions) and a class for adding the tallies. In main there is a counter of Tally data type. I'm unclear how to actually tally the votes. I have tried sending the counter.add function the GetIssue1 value, however this does not work.

    Code:
    #include <iostream>
    using namespace std;
    class Interface
    {
    private: 
    	int issue1;
    	int	issue2;
    	int issue3;
    public:
    	Interface(int=0,int=0,int=0);
    	~Interface(){};
    	void SetInterface(int i1,int i2, int i3);
    	void Setissue1();
    	void Setissue2();
    	void Setissue3();
    	int Getissue1();
    	int Getissue2();
    	int Getissue3();
    };
    Interface::Interface(int issue1,int issue2,int issue3)
    {
    	SetInterface(issue1,issue2,issue3);
    }
    void Interface::SetInterface(int i1, int i2, int i3)
    {
    
    }
    void Interface::Setissue1()
    {
    	int ans=0;
    		do
    		{
    		cout<<endl<<"Question 1: "<<endl;
    		cout<<"1) Do you use Microsoft Windows?"<<endl;
    		cin>>ans;
    			if (ans<0||ans>1)
    				cout<<"Please select 0 for NO or 1 for YES."<<endl;
    		}
    		while (ans<0||ans>1);
    	
    }
    void Interface::Setissue2()
    {
    	int ans=0;
    	do
    		{
    		cout<<endl<<"Question 2: "<<endl;
    		cout<<"2) Are you in favor of open source software?"<<endl;
    		cin>>ans;
    			if (ans<0||ans>1)
    				cout<<"Please select 0 for NO or 1 for YES."<<endl;
    		}
    		while (ans<0||ans>1);
    }
    void Interface::Setissue3()
    {
    	int ans=0;
    	do
    		{
    		cout<<endl<<"Question 3: "<<endl;
    		cout<<"3) Do you enjoy programming?"<<endl;
    		cin>>ans;
    			if (ans<0||ans>1)
    				cout<<"Please select 0 for NO or 1 for YES."<<endl;
    		}
    		while (ans<0||ans>1);
    }
    int Interface::Getissue1()
    {
    	return (issue1);
    }
    int Interface::Getissue2()
    {
    	return (issue2);
    }
    int Interface::Getissue3()
    {
    	return (issue3);
    }
    class Tally
    {
    private:
    	int issue1_y, issue1_n, issue2_y, issue2_n, issue3_y, issue3_n;
    public:
    	Tally();
    	~Tally(){};
    	int add1(int ans);
    	int add2(int ans);
    	int add3(int ans);
    };
    Tally::Tally()
    {
    	cout<<"Constructor"<<endl;
    	issue1_y=0;
    	issue1_n=0;
    	issue2_y=0;
    	issue2_n=0;
    	issue3_y=0;
    	issue3_n=0;
    }
    int Tally::add1(int ans)
    {
    	if (ans==0)
    	{
    		++issue1_n;
    	}
    	else if (ans==1)
    	{
    		++issue1_y;
    	}
    	cout<<"No: "<<issue1_n<<endl<<"Yes: "<<issue1_y<<endl;
    	return(0);
    }
    int Tally::add2(int ans)
    {
    	if (ans==0)
    		++issue2_n;
    	else if  (ans==1)
    		++issue2_y;
    	return (0);
    
    }
    int Tally::add3(int ans)
    {
    	if (ans==0)
    		++issue3_n;
    	else if (ans==1)
    		++issue3_y;
    	return (0);
    }
    void main()
    {
    	int num=0, ans=0, i=1;
    	Tally counter;
    	Interface Interface;
    	cout<<"Welcome to the tally program."<<endl;
    	cout<<"For all issues enter 0 for NO and 1 for YES."<<endl;
    	cout<<"How many voters do you have?"<<endl;
    	cin>>num;
    	do
    	{
    		cout<<endl<<"Voter: "<<i<<endl;
    		Interface.Setissue1();
    		Interface.Getissue1();
    		counter.add1(Interface.Getissue1());
    		Interface.Setissue2();
    		Interface.Getissue2();
    		counter.add2(Interface.Getissue2());
    		Interface.Setissue3();
    		Interface.Getissue3();
    		counter.add3(Interface.Getissue3());
    		--num;
    		++i;
    	}
    	while (num>0);
    }

    Thanks,
    J
  • Hypnotik
    New Member
    • Jun 2007
    • 87

    #2
    Problem has been resolved.

    J

    Comment

    Working...