离心机的使用方法图片:请教两道C++的编程题

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/04 07:27:25
1.矩形类其属性为矩形左下角与右上角两点坐标(由用户输入),要求能计算矩形的面积

2.设计一个用于人事管理的人员类,其属性为编号、姓名、出生日期、身份证,其中出生日期定义为一个日期类的内嵌子对象,用成员函数实现对人员信息的录入和显示,包括构造函数、析构函数、拷贝构造函数、内联成员函数、类默认形参的成员函数、类的组合。

第1题:
// 1.cpp
#include<iostream>
using namespace std;

int main()
{
double x1,x2,y1,y2;
cin>>x1>>x2>>y1>>y2;
cout<< (x2-x1)*(y2-y1)<<endl;
return 0;
}

第2题:精心设计,未经编译,顺手写的,完全符合所有要求了
//2 .cpp
#include<iostream>
#include<string.h>
using namespace std;

class mydate
{
public:
mydate(int y =1999, int m =1, int d =1):year(y), month(m), day(d)
{
}
mydate(mydate& a):year(a.year), month(a.month),day(a.day)
{
}
void input()
{
cout<<"Input Birthday Year:"<<ends;
cin>>year;
cout<<"Input Birthday Month:"<<ends;
cin>>month;
cout<<"Input Birthday Day:"<<ends;
cin>>day;
}

void output()
{
cout<<"Birthday is"<<year<<ends<<month<<ends<<day;
}
int year, month, day;

};
class Person
{
public:
Person()
{
Input();
}
Person(Person& a): _Number(a._Number), _Name(a._Name), _Birth(a._Birth), _Shenfenzheng(a._Shenfenzheng)
{
}
void Input()
{
cout<<"Input number:"<<ends;
cin>>_Number;
cout<<"Input name:"<<ends;
cin>>_Name;
_Birth.input();
cout<<"Input shenfenzheng:"<<ends;
cin>>_Shenfenzheng;
cout<<"Input Finished!"<<endl;
}

void output()
{
cout<<"Number is"<<ends<<_Number
<<"Name is"<<ends<<_Name;
_Birth.output();
cout<<"Shenfenzheng is"<<ends<<_Shenfenzheng<<endl;
}

int _Number;
string _Name;
mydate _Birth;
int _Shenfenzheng;
};

300分都不一定有人帮你
我说实话
这种事情该自己做

300分都不一定有人帮你
我说实话
这种事情该自己做
300分都不一定有人帮你
我说实话
这种事情该自己做
300分都不一定有人帮你
我说实话
这种事情该自己做
300分都不一定有人帮你
我说实话
这种事情该自己做
300分都不一定有人帮你
我说实话
这种事情该自己做
300分都不一定有人帮你
我说实话
这种事情该自己做

第一个问题的完整代码及例子;
在VC++下编译通过, 使用VC++建立一个简单的MFC工程,删除.CPP中全部代码换成下面:

#include "stdafx.h"
#include <afxWIN.h> // MFC extensions

class CMyRect{
private:
CRect rt;
long area;
public:
CMyRect(CPoint pt1,CPoint pt2){
CRect rt1(pt1,pt2);
rt=rt1;
area = rt.Width()*rt.Height();
}
long GetArea(void){return area;}

};

void main()
{
CMyRect mr(CPoint(0,0),CPoint(10,10));
cout<<mr.GetArea()<<endl;
}

第二个实在复杂了点.

这是一个类似的程序,你看看吧,希望有帮助;;;
#include <iostream.h>
#include <string.h>
#include <conio.h>

int adminLogin()
{

char s[80], adminPWD[]="123456",c; int k ;

cout<<"\n\n\t\t\t请输入管理员密码:";

cin>>s;

if( strcmp( s, adminPWD ) == 0 )
k=1; /*密码正确, 返回 */

else k=0;
return(k);

}

struct student
{
int no;
char name[12];
char classes[12];
char sex;
}tstudent;

void getinformation()
{ char s[80],c1;

for(; ;)
{
cout<<"\n\n\t\t\t请输入学号:";
cin>>tstudent.no;
if(tstudent.no<0)
{cout<<"\n\n\t\t\t您输入的学号错误!\n";
continue;
}

break;
}
for(; ;)
{
cout<<"\n\n\t\t\t请输入姓名:";
cin>>s;
if(strlen(s)>12)
{cout<<"\n\n\t\t\t您输入的姓名过长!\n";
continue;
}
strcpy(tstudent.name,s);
break;
}
for(; ;)
{
cout<<"\n\n\t\t\t请输入班级:";

cin>>s;
if(strlen(s)>12)
{
cout<<"\n\n\t\t\t对不起,班级名称过长!\n";
continue;
}
strcpy(tstudent.classes,s);
break;
}
for(; ;)
{
cout<<"\t\t\t请输入性别(m/f):";
cin>>c1;
if(c1!='m'&&c1!='f')
{
cout<<"\t\t\t性别输入错误!\n";
continue;
}
tstudent.sex=c1;
break;
}

}

void infoManage()
{
char c ;
for( ;; )
{
cout<<"\n\n\n\t\t\t\t信息维护"<<endl;
cout<<"\t\t\t 1、建立学生基本信息表\n";
cout<<"\t\t\t 2、建立学生成绩表\n" ;
cout<<"\t\t\t 3、添加学生记录\n";
cout<<"\t\t\t 4、删除学生记录\n";
cout<<"\t\t\t 5、修改学生记录\n";
cout<<"\t\t\t 0、返回\n\n";
cout<<"\t\t\t 请输入你的选择:" ;
cin>>c;
if( c == '0' ) return ;
else if( c == '1' ) getinformation();
else if( c == '2' ) ;
else if( c == '3' ) ;
else if( c == '4' ) ;
else if( c == '5' ) ;
}
}
void infoStatistics()
{
char c ;
for( ;; )
{
cout<<"\n\n\n\n\n\t\t\t信息统计";
cout<<"\t\t\t 1、成绩统计\n";
cout<<"\t\t\t 2、其它信息统计\n";
cout<<"\t\t\t 0、返回\n\n";
cout<<"\t\t\t 请输入你的选择:";
cin>>c;
if( c == '0' ) return ;
else if( c == '1' ) ;//statisCourse() ;
else if( c == '2' ) ;//statisOthers() ;
}
}
void infoRetrieve()
{
char c ;
for( ;; )
{
cout<<"\n\n\n\t\t\t信息检索"<<endl;
cout<<"\t\t\t 1、按姓名查找\n";
cout<<"\t\t\t 2、按班级查找\n" ;
cout<<"\t\t\t 3、按其它信息查找\n" ;
cout<< "\t\t\t 0、返回\n\n";
cout<<"\t\t\t 请输入你的选择:" ;
cin>>c;
if( c == '0' ) return ;
else if( c == '1' ) ;//retrieveByName() ;
else if( c == '2' ) ;//retrieveByClass() ;
else if( c == '3' ) ;//retrieveByOther() ;
}
}

void main()
{

char c ;
int adminLogin();

if( adminLogin() ==0) /* 检查管理员密码 */
goto Exit ;

/* 下面显示一级菜单 */
for( ;; )
{
cout<<"\n\n\n\n\n\n\t\t欢迎使用学生信息管理系统"<<endl;
cout<<"\t\t 1、信息维护\n";
cout<<"\t\t 2、信息检索\n";
cout<<"\t\t 3、信息统计\n";
cout<<"\t\t 0、退出系统\n\n";
cout<<"\t\t 请输入你的选择:";
cin>>c;
if( c == '0' ) goto Exit ;
else if( c == '1' ) infoManage();
else if( c == '2' ) infoRetrieve() ;
else if( c == '3' ) infoStatistics() ;
}
Exit:
cout<<"\n\n\n\t\t\t\t退出系统,再见。\n\n";
}