第十章编程练习(7)

来源:互联网 发布:lifemod软件下载 编辑:程序博客网 时间:2024/06/05 00:45

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;}


0 0