好文档 - 专业文书写作范文服务资料分享网站

C++上机实验报告实验四

天下 分享 时间: 加入收藏 我要投稿 点赞

.

{

name[0]=n; name[1]='\\0'; address[0]=a; address[1]='\\0'; city[0]=c; city[1]='\\0'; postcode=p; }

Employee::~Employee(){}

void Employee::change_name() {

cout<<\ cin.getline(name,15,'\\n'); }

void Employee::change_address() {

cout<<\ cin.getline(address,25,'\\n'); }

void Employee::change_city() {

cout<<\ cin.getline(city,10,'\\n'); }

void Employee::change_postcode() {

cout<<\ cin>>postcode; }

void Employee::display() {

cout<<\ cout<<\

cout<<\ cout<<\

cout<<\}

int main() {

Employee person(1,1,1,1); person.display(); person.change_name(); person.change_address();

.

.

person.change_city(); person.change_postcode(); person.display();

return 0; }

6.Employee.h

#ifndef Employee_H_INCLUDED #define Employee_H_INCLUDED

class Employee {

private:

char name[15]; char address[25]; char city[10]; int postcode; public:

Employee();

Employee(char n,char a,char c,int p); ~Employee();

void change_name(); void change_address(); void change_city(); void change_postcode(); void display(); };

#endif // Employee_H_INCLUDED

Employee.cpp

#include #include%using namespace std; Employee::Employee(){}

Employee::Employee(char n,char a,char c,int p) {

name[0]=n; name[1]='\\0'; address[0]=a; address[1]='\\0';

.

.

city[0]=c; city[1]='\\0'; postcode=p; }

Employee::~Employee(){}

void Employee::change_name() {

cout<<\ cin.getline(name,15,'\\n'); }

void Employee::change_address() {

cout<<\ cin.getline(address,25,'\\n'); }

void Employee::change_city() {

cout<<\ cin.getline(city,10,'\\n'); }

void Employee::change_postcode() {

cout<<\ cin>>postcode; }

void Employee::display() {

cout<<\ cout<<\

cout<<\ cout<<\

cout<<\}

int main() {

Employee

emp[5]={Employee(1,1,1,1),Employee(2,2,2,2),Employee(3,3,3,3),Employee(4,4,4,4),Employee(5,5,5,5)}; int i;

for(i=0;i<5;i++) {

emp[i].display(); emp[i].change_name(); emp[i].change_address();

.

.

emp[i].change_city(); emp[i].change_postcode(); cin.get(); }

for(i=0;i<5;i++) {

cout<<\ emp[i].display(); }

return 0; } 7.

#include #include using namespace std; //Date类 class Date {

private:

int year; int month; int day; public: Date();

Date(int y,int m,int d); Date(Date &p); ~Date();

void setDate(); void showDate(); };

//People类,其中含Date类型的数据 class People {

private:

char name[11]; char number[7]; char sex[3]; Date birthday; char id[16]; public:

People();

People(char* n,char* nu,char* s,Date b,char* i);

.

.

People(People &p); ~People();

void setName(); void setNumber(); void setSex(); void setId();

void showPeople(); };

//Date构造函数 Date::Date(){}

Date::Date(int y,int m,int d) {

year=y; month=m; day=d; }

Date::Date(Date &p) {

year=p.year; month=p.month; day=p.day; }

//析构

inline Date::~Date(){}

//Date成员函数,设置出生年月日 void Date::setDate() {

int y,m,d;

cout<<\ cin>>y;

cout<<\ cin>>m;

cout<<\ cin>>d; year=y; month=m; day=d; }

//Date联成员函数,输出年月日 inline void Date::showDate() {

cout<<\年\月\日\ }

//People构造函数

.

C++上机实验报告实验四

.{name[0]=n;name[1]='\\0';address[0]=a;address[1]='\\0';city[0]=c;city[1]='\\0';postcode=p;}Employee::~Employee(){}voidEmployee::
推荐度:
点击下载文档文档为doc格式
6csx63fn0g7f1wl0k4bu3bj0w6iihw013l8
领取福利

微信扫码领取福利

微信扫码分享