📄 prog5.cpp
字号:
#include <iostream.h>
#include <string.h>
class Book
{
char *title; //书名
char *author; //作者
int numsold; //月销售量
public:
Book() {}
Book(const char *str1,const char *str2,const int num)
{
int len=strlen(str1);
title=new char[len+1];
strcpy(title,str1);
len=strlen(str2);
author=new char[len+1];
strcpy(author,str2);
numsold=num;
}
void setbook(const char *str1,const char *str2,const int num)
{
int len=strlen(str1);
title=new char[len+1];
strcpy(title,str1);
len=strlen(str2);
author=new char[len+1];
strcpy(author,str2);
numsold=num;
}
~Book()
{
delete title;
delete author;
}
void print(ostream& output) //输出流引用作为参数
{
output << "输出数据" << endl;
output << " 书名:" << title << endl;
output << " 作者:" << author << endl;
output << " 月销售量:" << numsold << endl;
}
};
void main()
{
Book obj1("C语言程序设计","潭浩强",800),obj2;
obj1.print(cout);
obj2.setbook("C++语言程序设计","李春葆",300);
obj2.print(cout);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -