您的位置:首页 > 编程语言

第十章编程练习(7)

2016-02-05 19:37 260 查看
ff.h

#pragma once
#ifndef ff_H_
#define ff_H_
class Plorg {
private:
char name[19];
int cl;
public:
Plorg(char p_name[19] = "Plorga", int n = 50);
void setcl(int n);
void showpl()const;
};
#endif

function.cpp

#include "ff.h"
#include <iostream>
using namespace std;
Plorg::Plorg(char p_name[19], int n)
{
strcpy(name, p_name);
cl = n;
}
void Plorg::setcl(int n)
{
cl = n;
}
void Plorg::showpl()const
{
cout << "Name :" << name<<endl
<< "CL :" << cl<<endl;
}


main.cpp

#include <iostream>
#include "ff.h"
#include <cstdlib>
using namespace std;
int main()
{
Plorg pl;
pl.showpl();
cout << "Please enter your name: ";
char name[19];
cin.getline(name, 19);
Plorg sl(name);
sl.showpl();
cout << "Please enter your CL: ";
int n = 0;
cin >> n;
sl.setcl(n);
sl.showpl();
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: