?? 練習(xí).txt
字號:
11.2
//*********************
//** Cat.h **
//*********************
class Cat
{
public:
int GetAge();
void SetAge(int age);
void Meow();
protected:
int itsAge;
};
//***********************
//** Cat.cpp **
//***********************
#include <iostream.h>
#include "Cat.h"
int Cat::GetAge()
{
return itsAge;
}
void Cat::SetAge(int age)
{
itsAge=age;
}
void Cat::Meow()
{
cout<<"Meow."<<endl;
}
//************************
//** main.cpp **
//************************
#include <iostream.h>
#include "Cat.h"
void main()
{
Cat frisky;
frisky.SetAge(5);
frisky.Meow();
cout<<"frisky is a cat who is "
<<frisky.GetAge()
<<" years old."<<endl;
frisky.Meow();
}
11.3
//**********************
//** Date.h **
//**********************
//class declaration
class Date
{
public:
void Set(int d,int m,int y);
void Disp();
void IncOneDay();
protected:
int day;
int month;
int year;
};
//************************
//** Date.cpp **
//************************
#include <iostream.h>
#include "Date.h"
void Date::Set(int d,int m,int y)
{
day=d;
month=m;
year=y;
}
void Date::Disp()
{
cout<<day<<"/"<<month<<"/"<<year<<endl;
}
void Date::IncOneDay()
{
day+=1;
}
//************************
//** main.cpp **
//************************
#include <iostream.h>
#include "Date.h"
void main()
{
Date current;
current.Set(15,3,1998);
current.Disp();
current.IncOneDay();
current.Disp();
}
11.4
//**********************
//** Time.h **
//**********************
//class time.h declaration
#include <iostream.h>
class Time
{
public:
void Set(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
}
void Disp()
{
cout<<"time "<<hour<<":"<<minute<<":"<<second<<endl;
}
protected:
int hour;
int minute;
int second;
};
//************************
//** main.cpp **
//************************
//#include <iostream.h>
#include "Time.h"
void main()
{
Time cur;
cur.Set(20,22,22);
cur.Disp();
}
11.5
//***********************
//** Stack.h **
//***********************
//class Stack.h declaration
struct Node
{
int a;
Node* next;
};
class Stack
{
public:
void put(int item);
int get();
protected:
Node* tmp;
}; //the symble ";" here is very important!!!
//*************************
//** Stack.cpp **
//*************************
#include "Stack.h"
void Stack::put(int item)
{
Node* n=new Node;
n->a=item;
n->next=tmp;
tmp=n;
}
int Stack::get()
{
int tmp_val;
tmp_val=tmp->a;
tmp=tmp->next;
return tmp_val;
}
//************************
//** main.cpp **
//************************
#include <iostream.h>
#include "Stack.h"
void main()
{
Stack st;
st.put(10);
st.put(12);
st.put(14);
cout<<st.get()<<endl;
cout<<st.get()<<endl;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -