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

📄 00.txt

📁 Design and test a category called Rectangle rectangular, rectangular attribute to the lower left cor
💻 TXT
字号:
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.
# include "iostream.h"
void main()
{
	int n[]={5,7,1,9,10};
	int max=n[0];
	for(int i=1;i<5;i++)
		if(n[i]>max)
			max=n[i];
		cout<<"The max number is: "
			<<endl
			<<max
			<<endl;
}

22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
#include<iostream> 
using namespace std; 
void fun(char *p) 
{int num=0; 
 while(*p!='\0') 
 {if('0'<=*p&&*p<='9') 
 num++; 
 p++; 
 } 
 cout <<endl <<"number:" <<num <<endl;
} 
 int main() 
{char input[80]; 
 int i=0; 
 while((input[i]=cin.get())!='\n') 
 {cout.put(input[i]); 
 i++; 
 } 
 fun(input); 
 return 0; 
 } 
333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
解: 
拷贝构造函数是一种特殊的构造函数,具有一般构造函数的所有特性,其形参是本类的对象的引用,其作用是使用一个已经存在的对象,去初始化一个新的同类的对象。在以下三种情况下会被调用:在当用类的一个对象去初始化该类的另一个对象时;如果函数的形参是类对象,调用函数进行形参和实参结合时;如果函数的返回值是类对象,函数调用完成返回时;



4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
#include <iostream.h>
class Rectangle
{
public:
Rectangle (int top, int left, int bottom, int right);
~Rectangle () {}

int GetTop() const { return itsTop; }
int GetLeft() const { return itsLeft; }
int GetBottom() const { return itsBottom; }
int GetRight() const { return itsRight; }

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

int GetArea() const;

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

int Rectangle::GetArea() const
{
int Width = itsRight-itsLeft;
int Height = itsTop - itsBottom;
return (Width * Height);
}

int main()
{
int x1,y1,x2,y2;
cout <<"putin x1 y1 x2 y2 please:";
cin >>x1 >>y1 >>x2 >>y2;
Rectangle MyRectangle (y1, x1, y2, x2 );
int Area = MyRectangle.GetArea();
if(Area<0)
cout <<"you type wrong number" <<endl;
else
cout << "Area is  " << Area <<endl;
return 0;
}

555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
#include "stdafx.h" 
#include "iostream" 
#include "string" 
using namespace std; 

class Data{//日期类 
public: 
Data(){} 
Data(int y,int m,int d){ 
m_year=y; 
m_month=m; 
m_day=d; 
} 
int get_year(){ 
return m_year; 
} 
int get_month(){ 
return m_month; 
} 
int get_day(){ 
return m_day; 
} 
void set_year(int y){ 
m_year=y; 
} 
void set_month(int m){ 
m_month=m; 
} 
void set_day(int d){ 
m_day=d; 
} 
private: 
int m_year; 
int m_month; 
int m_day; 
}; 

class Person{//人员类 
public: 
Person(){} 
Person(int n,int sex, Data birth, string id){//构造函数 
m_number=n; 
m_sex=sex; 
m_birthday=birth; 
m_id=id; 
} 
Person(Person *temp){//拷贝构造函数 
m_number=temp->get_number(); 
m_sex=temp->get_sex(); 
m_birthday=temp->get_birthday(); 
m_id=temp->get_id(); 
} 
~Person(){ 
} 
inline int get_number(){//内联成员函数 
return m_number; 
} 
int get_sex(){ 
return m_sex; 
} 
Data get_birthday(){ 
return m_birthday; 
} 
string get_id(){ 
return m_id; 
} 
Person addperson(){//人员信息的录入 
int number,sex,year,month,day; 
string id; 
cout<<"Please input the number of the employee:"; 
cin>>number; 
cout<<"Please input the sex of the employee (1 for male, 0 for female):"; 
cin>>sex; 
cout<<"Please input the birthday of the employee,\n" 
<<"for example,\"1984 7 21\"\n"; 
cin>>year>>month>>day; 
cout<<"Please input the id of the employee:"; 
cin>>id; 
Data birthday(year,month,day); 
m_number=number; 
m_sex=sex; 
m_birthday=birthday; 
m_id=id; 
return this; 
} 
void show(){//人员信息的显示 
string sex=m_sex>0?"male":"female"; 
cout<<endl; 
cout<<"Number: "<<m_number<<endl; 
cout<<"Sex:"<<sex<<endl; 
cout<<"Birthday:"<<m_birthday.get_year()<<"-" 
<<m_birthday.get_month()<<"-" 
<<m_birthday.get_day()<<endl; 
cout<<"ID: "<<m_id<<endl; 
} 
private: 
int m_number; 
int m_sex; 
Data m_birthday;//日期类 内嵌子对象 
string m_id; 
}; 
int _tmain(int argc, _TCHAR* argv[]) 
{ 
Person p; 
p.addperson(); 
p.show(); 
return 0; 
}
66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
#include <iostream.h>

class datatype{
enum{
character,
integer,
floating_point
} vartype;
union 
{
char c;
int i;
float f;
};
public:
datatype(char ch) {
vartype = character;
c = ch;
}
datatype(int ii) {
vartype = integer;
i = ii;
}
datatype(float ff) {
vartype = floating_point;
f = ff;
}
void print();
};

void datatype::print() {
switch (vartype) {
case character:
cout << "字符型: " << c << endl;
break;
case integer:
cout << "整型: " << i << endl;
break;
case floating_point:
cout << "浮点型: " << f << endl;
break;
}
}

void main() {
datatype A('c'), B(12), C(1.44F);
A.print();
B.print();
C.print();
}

7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777

⌨️ 快捷键说明

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