⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rectangle.txt

📁 1.设计一个时间类(年、月、日、时、分); 设计一个通知类
💻 TXT
字号:
1.矩形类:
#include <iostream.h> 
#include <math.h> 

class Rectangle 
{ 
public: 
Rectangle(int left,int bottom,int right,int top); 
~Rectangle(){ } 
//int GetLeft() {return itsLeft;} 
int GetBottom() {return itsBottom;} 
int GetRight() {return itsRight;} 
int GetTop() { return itsTop;} 

void SetLeft(int left) {itsLeft=left;} 
void SetBottom(int bottom) {itsBottom=bottom;} 
void SetRight(int right) {itsRight=right;} 
void SetTop(int top) {itsTop=top;} 

int GetArea(); 
private: 
int itsLeft; 
int itsBottom; 
int itsRight; 
int itsTop; 
int Width; 
int Height; 
}; 
Rectangle::Rectangle(int left,int bottom,int right,int top) 
{ 
itsLeft=left; 
itsBottom=bottom; 
itsRight=right; 
itsTop=top; 
} 

int Rectangle::GetArea() 
{ 
Width=abs(itsRight-itsLeft); 
Height=abs(itsTop-itsBottom); 
cout<<"该矩形的长:"<<Width<<endl; 
cout<<"该矩形的宽:"<<Height<<endl; 
return (Width*Height); 
} 

void main() 
{ 
Rectangle MyRectangle(20,20,60,50); 
int Area; 
Area=MyRectangle.GetArea(); 
cout<<"Area:"<<Area<<endl; 
MyRectangle.SetLeft(10); 
Area=MyRectangle.GetArea(); 
cout<<"Area:"<<Area<<endl; 
}
2.通知类:
.#include<iostream>
#include<string>
using namespace std;
class time
{private:
      int Year,Moth,Day,Hour,Mint;
 public:
	time(int _Year,int _Moth,int _Day,int _Hour,int _Mint)
	{Year=_Year;Moth=_Moth;Day=_Day;Hour=_Hour;Mint=_Mint;}
	 void input()
	 { 
		 cin>>Year>>Moth>>Day>>Hour>>Mint;}
	 void display()
	 {cout<<"time:"<<Year<<"/"<<Moth<<"/"<<Day<<" "<<Hour<<":"<<Mint<<endl;}
};
class notice
{private:
      time T;
      string Str1,Str2;
 public:
	 notice(time xT,string xStr1,string xStr2);
     //notice(notice &);
	 //void display();
};
notice::notice(time xT,string xStr1,string xStr2):T(xT),Str1(xStr1),Str2(xStr2)
{
	T.display();
	cout<<"  地点:"<<Str1<<"  事件:"<<Str2<<endl;
};
int main()
{
	time T1(2007,10,18,12,30);
	string xStr1,xStr2;
	notice N1(T1,"理A","上课");
	cout<<"请输入时间:";
	T1.input();
	cout<<"请输入地点:";
	cin>>xStr1;
	cout<<"请输入事件:";
	cin>>xStr2;
	notice N2(T1,xStr1,xStr2);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -