Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,914 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,587 people online right now. Registration is fast and FREE... Join Now!




cat status

 
Reply to this topicStart new topic

cat status, I need to have the cat do 3 different things with 3 different integers

jvosa
16 May, 2008 - 04:36 AM
Post #1

New D.I.C Head
*

Joined: 12 May, 2008
Posts: 5

CODE

#include <iostream.h>

class cat
{
public:
cat (int a)
~cat
int age;
int status;

void meow();
void sleep();
void wake();
void fight();
};

void cat::meow()
{
if (status==1)
{
cout<<"zzzzz...\n"<<endl;
}
else
{
cout<<" meow!!!!...\n"<<endl;
}
}

void cat::sleep()
{
if (status==1)
  {
   cout<<" zzzz......\n"<<endl;
  }
else
   {
   cout<< " good night! zzzzz....!\n "<<endl;
   status=1;
   }
}

void cat::wake()
{
  if (status==0)
  {
  cout<< " hi! nice to see you \n "<<endl;
  }
  else
  {
  cout<<" aaaaaaah.... Good morning! \n "<<endl;
       status=0;
  }
}

int main()
{
  cat frisky;
  int what=0;
  
  frisky.wake();
  cout<<" Hello! how old is your cat?";
  cin>>frisky.age;
  cout<<" thank you! \n "<<endl;
  
cout<<" press 1 to meow, 2 to sleep, 3 to wake, 4 to end"<<endl;
cin>>what;

while (what!=4)
  {
    if (what==1)
      {
     frisky.meow();
      }
    else if (what==2)
      {
     frisky.sleep();
      }
    else if (what==3)
      {
     frisky.wake();
      }
  
      
cin>>what;  
      }


   {
  cout<<endl;
  cout<<" meow! bye all "<<endl;
  what==6
   }

return 0;

}


what i wrong with this i have an error in line 7 that says illegal type

can you please help me???!!!

This post has been edited by jvosa: 16 May, 2008 - 04:37 AM
User is offlineProfile CardPM
+Quote Post

skater_00
RE: Cat Status
16 May, 2008 - 05:27 AM
Post #2

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
The following code is error-free, but I'm not 100% sure if it's this that you want.

EDIT: Edited your code to what I think it is supposed to do now.

cpp

#include <iostream>

using namespace std;

class Cat
{
public:
Cat();
virtual ~Cat();

void Meow();
void Sleep();
void Wake();

int m_Age; // *** This variable is better off protected, but I can't get FriskyPtr to access it then. ***

private:
int m_Status;
bool m_Sleeping;

Cat(const Cat& t);
Cat& operator=(const Cat& t);
};

Cat::Cat():m_Age(0), m_Status(0), m_Sleeping(false)
{

}

Cat::~Cat()
{

}

void Cat::Meow()
{
if (m_Sleeping)
cout << endl << "Zzz..." << endl << endl;
else
cout << endl << "Meow!..." << endl << endl;
}

void Cat::Sleep()
{
if (m_Sleeping)
cout << endl << "Zzz..." << endl << endl;
else {
cout << endl << "Good night! Zzz..." << endl << endl;
m_Sleeping = true;
}
}

void Cat::Wake()
{
if (m_Sleeping) {
m_Sleeping = false;
cout << endl << "Aah... Good morning!" << endl << endl;
} else
cout << endl << "Hi! Nice to see you again." << endl << endl;
}

int main()
{
Cat * FriskyPtr = new Cat();
int Input(0);

cout << "Hello! How old is your cat? ";
cin >> FriskyPtr->m_Age;
cout << endl << "Thank you!" << endl << endl;

while (Input != 4) {
cout << "Press 1 to Meow, 2 to Sleep, 3 to Wake or 4 to Quit: ";
cin >> Input;

switch (Input)
{
case 1:
FriskyPtr->Meow();
break;
case 2:
FriskyPtr->Sleep();
break;
case 3:
FriskyPtr->Wake();
break;
default:
break;
}
}

cout << endl << "Meow! Bye all!" << endl << endl;

delete FriskyPtr;

system("PAUSE");
return 0;
}


This post has been edited by skater_00: 16 May, 2008 - 05:54 AM
User is offlineProfile CardPM
+Quote Post

jvosa
RE: Cat Status
19 May, 2008 - 04:10 AM
Post #3

New D.I.C Head
*

Joined: 12 May, 2008
Posts: 5

ok thank you but that is not what i needed... i need to know what is the error that does not allow me to run the program and i said it's in line 7 so pls help me!!!!! thnks
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Cat Status
19 May, 2008 - 04:27 AM
Post #4

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,514



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
Your destructor has to be a type, try replacing ~cat with ~cat();

Also, you might want to consider indenting you code, it makes it much easier to read smile.gif

Hope this helps.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 07:57AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month