C++ Logo
C++二级在线二级在线
首页选择题程序题成为会员帮助其他科目

乐章修复记

请修改编辑器中的代码,完成以下功能:程序定义了一个名为 Symphony 的类,用于表示交响乐作品。每个 Symphony 对象包含标题、作者和乐章数量的信息。程序应正确输出两个交响乐作品的信息,分别是贝多芬的“c小调第五交响乐.命运”和莫扎特的“g小调第四十交响乐”,每个作品有 4 个乐章。 不需要输入。 输出示例: 贝多芬的c小调第五交响乐.命运有4个乐章 莫扎特的g小调第四十交响乐有4个乐章

#include <iostream>
#include <cstring> 
#pragma warning (disable:4996)
using namespace std;

class Symphony		//“交响乐”类
{
public:
	Symphony(char *str1, char *str2, int count=4);
	// ERROR **********found**********
	void ~Symphony();
	void Display() const;
private:
	char *title;			//交响乐名称
	// ERROR **********found**********
	char author[];			//交响乐作者
	const int movement;		//乐章数
};
// ERROR **********found**********
Symphony::Symphony(char *str1, char *str2,int count=4):movement(count)
{
	title=new char[strlen(str1)+1];
	strcpy(title,str1);
	author=new char[strlen(str2)+1]; 
	strcpy(author,str2);
}
Symphony::~Symphony()
{
	delete[] title;
	delete[] author;
}
void Symphony::Display() const
{
	cout<<author<<"的"<<title<<"有"<<movement<<"个乐章"<<endl;
}
int main()
{
	Symphony s1("c小调第五交响乐.命运","贝多芬",4),
		     s2("g小调第四十交响乐","莫扎特",4);
	s1.Display();
	s2.Display();
	return 0;
}

控制台

调试终端

准备就绪