Twigz's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
Active Members
Active Posts:
59 (0.06 per day)
Joined:
11-July 11
Profile Views:
1,020
Last Active:
User is offline May 12 2012 12:04 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Twigz has not set their status

Posts I've Made

  1. In Topic: Task/Problem Using classes

    Posted 10 May 2012

    I see, well which other book would u recommend? I'm looking for another book to go through. Need a very good book to complement it.
  2. In Topic: Task/Problem Using classes

    Posted 10 May 2012

    Yep that's the only book I'm using. Why do you ask?
  3. In Topic: Task/Problem Using classes

    Posted 9 May 2012

    Oh it's, Beginning C++ Through Game Programming third edition by Michael Dawson.
  4. In Topic: Task/Problem Using classes

    Posted 9 May 2012

    View PostX23Y19, on 09 May 2012 - 07:26 PM, said:

    What is the main C++ you are working with @ Twigz.


    it was displayed in my first post.

    //Critter Caretaker
    //Simulates caring for a virtual pet
    
    #include <iostream>
    
    using namespace std;
    
    class Critter
    {
    public:          
        Critter(int hunger = 0, int boredom = 0); 
        void Talk();
        void Eat(int food = 4);
        void Play(int fun = 4);
    
    private:
        int m_Hunger;
        int m_Boredom;
    
        int GetMood() const;
        void PassTime(int time = 1);
    
    };
    
    Critter::Critter(int hunger, int boredom):
        m_Hunger(hunger),
        m_Boredom(boredom)
    {}
    
    inline int Critter::GetMood() const 
    {
        return (m_Hunger + m_Boredom);
    }
    
    void Critter::PassTime(int time)
    {
        m_Hunger += time;
        m_Boredom += time;
    }
    
    void Critter::Talk()
    {
        cout << "I'm a critter and I feel ";
    
        int mood = GetMood();
        if (mood > 15)
    	{
            cout << "mad.\n";
    	}
        else if (mood > 10)
    	{
            cout << "frustrated.\n";
    	}
        else if (mood > 5)
    	{
            cout << "okay.\n";
    	}
        else
    	{
            cout << "happy.\n";
    	}
    
        PassTime();
    }
    
    void Critter::Eat(int food) 
    {
        cout << "Brruppp.\n";
    
        m_Hunger -= food;
        if (m_Hunger < 0)
    	{
            m_Hunger = 0;
    	}
    
        PassTime();
    }
    
    void Critter::Play(int fun)
    {
        cout << "Wheee!\n";
    
        m_Boredom -= fun;
        if (m_Boredom < 0)
    	{
            m_Boredom = 0;
    	}
    
        PassTime();
    }
    
    int main()
    {
        Critter crit;
    
        int choice = 1;  //start the critter off talking
        while (choice != 0)
        {
            cout << "\nCritter Caretaker\n\n";
            cout << "0 - Quit\n";
            cout << "1 - Listen to your critter\n";
            cout << "2 - Feed your critter\n";
            cout << "3 - Play with your critter\n\n";
    
            cout << "Choice: ";
            cin >> choice;
    
            switch (choice)
            {
            case 0:	
                cout << "Good-bye.\n";
    			break;
            case 1:	
                crit.Talk();
    			break;
            case 2:	
                crit.Eat();
    			break;
            case 3:	
                crit.Play();
    			break;
            default:
                cout << "\nSorry, but " << choice << " isn't a valid choice.\n";
            }
        }
    
        return 0;
    }
    
    
    
    
  5. In Topic: Task/Problem Using classes

    Posted 9 May 2012

    ok now for "void Play(int food = 4);" Umm thats how the original file had it, so i'm not sure whether thats what needs to be changed.

    I think i figured out something.

    for these pieces of code:

    void Critter::Eat(int food)
    {
    	cout << "Brrupppp.\n";
    	m_Hunger -= food;
    	ShowHungerBoredom(); // This should not be here
    	if (m_Hunger < 0)
    	{
    		m_Hunger = 0;
    	}
    
    	                     // It should be here
    	PassTime();
    }
    
    void Critter::Play(int fun)
    {
    	cout << "Wheeeee!\n";
    	m_Boredom -=fun;
    	ShowHungerBoredom(); // This should not be here
    	if (m_Boredom < 0)
    	{
    		m_Boredom = 0;
    	}
    
    	                     // It should be here
    	PassTime();
    }
    


    in this version the program would display ShowHungerBoredom() before it reaches the if statement. So it would display the negative number first before it adjust the value to 0. If Hunger or boredom were to end up less than 0, the if statement would then automatically adjust the value to 0.


    but int his version the program would display ShowHungerBoredom() after the if statement. And if the value of hunger or boredom were to end up less than 0 the if statement would correct it to 0.

    void Critter::Eat(int food)
    {
    	cout << "Brrupppp.\n";
    	m_Hunger -= food;
    	
    	if (m_Hunger < 0)
    	{
    		m_Hunger = 0;
    	}
    
    	ShowHungerBoredom();
    	PassTime();
    }
    
    void Critter::Play(int fun)
    {
    	cout << "Wheeeee!\n";
    	m_Boredom -=fun;
    	
    	if (m_Boredom < 0)
    	{
    		m_Boredom = 0;
    	}
    
    	ShowHungerBoredom();
    	PassTime();
    }
    


    By the way here is my completed version. Please point out if i made a mistake any where thank you.

    // Critter Caretaker
    // Simulates caring for a virtual pet
    
    #include<iostream>
    
    using namespace std;
    
    class Critter
    {
    public:
    	Critter(int Hunger = 0, int Boredom = 0 );
    	void Talk();
    	void Eat(int food = 4);
    	void Play(int food = 4);
    	void ShowHungerBoredom();
    	
    private:
    	int m_Hunger;
    	int m_Boredom;
    
    	int GetMood() const;
    	void PassTime(int time = 1);
    };
    
    Critter::Critter( int hunger, int boredom ):
    	m_Hunger(hunger),
    	m_Boredom(boredom)
    {}
    
    inline int Critter::GetMood() const
    {
    	return (m_Hunger + m_Boredom);
    }
    
    void Critter::PassTime( int time )
    {
    	m_Hunger += time; 
    	m_Boredom += time;
    }
    
    void Critter::Talk()
    {
    	cout << "I'm a critter and i feel ";
    
    	int mood = GetMood();
    	if (mood > 21)
    	{
    		cout << "mad.\n";
    		
    	}
    	else if (mood > 16)
    	{
    		cout << "frustrated.\n";
    		
    	}
    	else if (mood > 7)
    	{
    		cout << "okay.\n";
    		
    	}
    	else
    	{
    		cout << "happy.\n";
    		
    	}
    
    	ShowHungerBoredom();
    	PassTime();
    }
    
    void Critter::Eat(int food)
    {
    	cout << "Brrupppp.\n";
    	m_Hunger -= food;
    	
    	if (m_Hunger < 0)
    	{
    		m_Hunger = 0;
    	}
    
    	ShowHungerBoredom();
    	PassTime();
    }
    
    void Critter::Play(int fun)
    {
    	cout << "Wheeeee!\n";
    	m_Boredom -=fun;
    	
    	if (m_Boredom < 0)
    	{
    		m_Boredom = 0;
    	}
    
    	ShowHungerBoredom();
    	PassTime();
    }
    
    void Critter::ShowHungerBoredom()
    {
    	if ((m_Hunger <= 3) && (m_Boredom <= 3))
    	{
    		cout <<  "I'm Not hungry nor bored.\n\n";
    		cout << "Values: " << m_Hunger << "." << m_Boredom << "\n\n";
    	}
    	else if ((m_Hunger <= 3) && ((m_Boredom > 3 && m_Boredom <= 11)))
    	{
    		cout <<  "I'm Not hungry, but i'm a little bored.\n\n";
    		cout << "Values: " << m_Hunger << "." << m_Boredom << "\n\n";
    	}
    	else if ((m_Hunger <= 3) && (m_Boredom >= 11))
    	{
    		cout << "I'm Not hungry, but i'm really Bored.\n\n";
    		cout << "Values: " << m_Hunger << "." << m_Boredom << "\n\n";
    	}
    	else if ((m_Boredom <= 3) && ((m_Hunger > 3 && m_Hunger < 11)))
    	{
    		cout << "I'm a little hungry but not bored.\n\n";
    		cout << "Values: " << m_Hunger << "." << m_Boredom << "\n\n";
    	}
    	else if (((m_Boredom > 3 && m_Boredom < 11)) && ((m_Hunger > 3 && m_Hunger < 11)))
    	{
    		cout << "I'm a little hungry and bored.\n\n";
    		cout << "Values: " << m_Hunger << "." << m_Boredom << "\n\n";
    	}
    	else if ((m_Boredom >= 11) && ((m_Hunger > 3 && m_Hunger < 11)))
    	{
    		cout << "I'm a little hungry, but really bored.\n\n";
    		cout << "Values: " << m_Hunger << "." << m_Boredom << "\n\n";
    	}
    	else if ((m_Hunger >= 11) && (m_Boredom <= 3))
    	{
    		cout << "I'm really hungry, but not bored.\n\n";
    		cout << "Values: " << m_Hunger << "." << m_Boredom << "\n\n";
    	}
    	else if ((m_Hunger >= 11) && ((m_Boredom > 3 && m_Boredom < 11)))
    	{
    		cout << "I'm really hungry and a little bored.\n\n";
    		cout << "Values: " << m_Hunger << "." << m_Boredom << "\n\n";
    	}
    	else if ((m_Hunger >= 11) && (m_Boredom >= 11))
    	{
    		cout << "I'm really hungry and really bored.\n\n";
    		cout << "Values: " << m_Hunger << "." << m_Boredom << "\n\n";
    	}
    }
    
    int main()
    {
    	Critter crit;
    	crit.Talk();
    
    	int choice;
    	do
    	{
    		cout << "\nCritter Caretaker\n\n";
    		cout << "0 - Quit\n";
    		cout << "1 - Listen to your critter\n";
    		cout << "2 - Feed your critter\n";
    		cout << "3 - Play with critter\n";
    
    		cout << "Choice: ";
    		cin >> choice;
    
    		switch(choice)
    		{
    		case 0:
    			cout << "Good-bye. \n";
    			break;
    		case 1:
    			crit.Talk();
    			break;
    		case 2:
    			crit.Eat();
    			break;
    		case 3:
    			crit.Play();
    			break;
    		default:
    			cout << "\nSorry, but " << choice << " isn't a valid choice.\n";
    		}
    	}while (choice != 0);
    
    	return 0;
    }
    
    
    

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

Twigz has no profile comments yet. Why not say hello?