--> Frank Masingill wrote to Cliff Rhodes <--
FM>#include
FM>#include
FM>
FM>class Humanoid // declare a class
FM>{
FM> public: // visible anywhere in program
FM> int GetAge(); // public function
FM> void SetAge(int Age); // public function
FM> void Philosopher(); // public function
FM>
FM> private: // accessible ONLY within the class
FM> Humanoid int She_He_Its_Age; //member variable
FM>};
FM>
FM> int Humanoid ::GetAge() // return value of this private
FM> member { // of the class
FM> return She_He_Its_Age;
FM> }
FM>
FM> void Humanoid::SetAge(int Age) //define SetAge
FM> {
FM> She_He_Its_Age = Age; // Set the age of the
FM> humanoid }
FM> void Humanoid::Philosopher() // member function to define
FM> the { // humanoid by what he
FM> says cprintf("Why is their something and not nothing?.");
FM> }
FM>
FM>int main()
FM>{
FM> Humanoid Frank; //instantiate Johnny as name-like object
FM> Frank.SetAge(65); //call member function to set the age
FM> Frank.Philosopher(); //call member function for characteristic
FM> of // a philosopher
FM>
FM> clrscr();
FM>
FM> gotoxy(10,5);
FM> textcolor(11);
FM> cprintf("Frank HAS to be frank because that's his middle
FM> name."); gotoxy(10,6);
FM> cprintf("Frank is a humanoid who is ");
FM> gotoxy(10,7);
FM>
FM>//*****************************************************************
FM>//****** THIS NEXT LINE - HOW DO I GET COLOR IN ENTIRE LINE?
FM>//*****************************************************************
FM>//*****
FM> cout << Frank.GetAge() << " years old.\n";
FM> gotoxy(10,8);
FM> cprintf("and he goes around all the time saying things like " );
FM> gotoxy(10,9);
FM>//*****************************************************************
FM>//****** AND IN THIS ONE BELOW
FM>//*****************************************************************
FM> ****** Frank.Philosopher();
FM> return 0;
FM>}
Frank, you are mixing old style C console output with C++ stream
output. You can't do what you want that way. Here is a 'Borlandized'
version that uses their constream class to do what you want:
#include
#include // ** I included this! **
class Humanoid
public:
int GetAge();
void SetAge(int Age);
// ** I changed the philosopher member! **
const char * Philosopher();
private:
int She_He_Its_Age;
};
int Humanoid ::GetAge()
{
return She_He_Its_Age;
}
void Humanoid::SetAge(int Age)
{
She_He_Its_Age = Age;
}
// ** Changed implementation **
const char * Humanoid::Philosopher()
{
// ** Now it just returns the address of the string **
return "Why is their something and not nothing?.";
}
int main(void)
{
constream cs; // ** Added this! **
Humanoid Frank;
Frank.SetAge(65);
cs.clrscr(); // ** Now clear the constream! **
/* Instead of cout, or cprintf, I just streamed out to the
* constream, cs. It has manipulators (dedicated functions)
* that let you change the stream properties. For instance,
* setxy() is the same as gotoxy, except it works on a stream.
* setclr() sets the color.
*
* This is a lot more 'C++ like' than mixing standard cout and
* and cprintf() statements.
*/
cs << setxy(10, 5) << setclr(11) <<
"Frank HAS to be frank because that's his middle name.";
cs << setxy(10, 6) << "Frank is a humanoid who is ";
cs << setxy(10, 7) << Frank.GetAge() << " years old.\n";
cs << setxy(10, 8) <<
"and he goes around all the time saying things like ";
cs << setxy(10, 9) << Frank.Philosopher();
return 0;
}
Cliff Rhodes
cliff.rhodes@juge.com
crhodes@flash.net
X CMPQwk 1.42 1692 X"Man is a hating rather than loving animal." - Rebecca
West
--- Maximus/2 3.01
---------------
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
|