当前位置:编程学习 > C#/ASP.NET >>

一道c++题目求解

#include<iostream>
#include<string>
using namespace std;
class Publication
{
private:
string title;
string name;
float price;
string date;
public:
Publication(){cout<<"Publication::Publication() called.\n";}
void inputData(string t,string n,float p,string d)
{
title=t;name=n;price=p;date=d;
}
void display()
{
cout<<title<<" "<<name<<" "<<price<<" "<<date<<endl;
}
~Publication(){cout<<"Publication::~Publication() called.\n";}

};
class Book:public Publication
{
private:
int page;
public:
Book(){cout<<"Book::Book() called.\n";}
void inputData(int p1)
{
page=p1;
}

void display()
{
cout<<page<<endl;
}

~Book(){cout<<"Book::~Book() called.\n";}


};
class Tape:public Publication
{
private:
string playtime;
public:
Tape(){cout<<"Tape::Tape() called.\n";}
void inputData(string p2)
{
 playtime=p2;
}
void display()
{cout<<playtime<<endl;}

~Tape(){cout<<"Tape::~Tape() called.\n";}

};
void main()
{
string t="出版物标题";
string n="出版物名称";
float  p=1000;
string d="日期";
int  p1=100;
string p2="播放时间";
Publication();
Book();
Tape();
Publication A;
A.inputData();
A.display();
Book B;  
B.inputData();  
B.display();  
Tape T;  
T.inputData();  
T.display();  
 

} 求解 --------------------编程问答-------------------- 问题是什么? --------------------编程问答-------------------- 问题呢。。。。。 --------------------编程问答-------------------- 貌似是定义的类没有参数 --------------------编程问答--------------------
// CppApp1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include<iostream>
#include<string>
using namespace std;
class Publication
{
private:
string title;
string name;
float price;
string date;
public:
Publication(){cout<<"Publication::Publication() called.\n";}
void inputData(string t,string n,float p,string d)
{
title=t;name=n;price=p;date=d;
}
void display()
{
cout<<title<<" "<<name<<" "<<price<<" "<<date<<endl;
}
~Publication(){cout<<"Publication::~Publication() called.\n";}

};
class Book:public Publication
{
private:
int page;
public:
Book(){cout<<"Book::Book() called.\n";}
void inputData(int p1)
{
page=p1;
}

void display()
{
cout<<page<<endl;
}

~Book(){cout<<"Book::~Book() called.\n";}


};
class Tape:public Publication
{
private:
string playtime;
public:
Tape(){cout<<"Tape::Tape() called.\n";}
void inputData(string p2)
{
playtime=p2;
}
void display()
{cout<<playtime<<endl;}

~Tape(){cout<<"Tape::~Tape() called.\n";}

};
int _tmain(int argc, _TCHAR* argv[])
{
string t="出版物标题";
string n="出版物名称";
float  p=1000;
string d="日期";
int  p1=100;
string p2="播放时间";
Publication();
Book();
Tape();
Publication A;
A.inputData(t, n, p, d);
A.display();
Book B;  
B.inputData(p1);  
B.display();  
Tape T;  
T.inputData(p2);  
T.display();
}
补充:.NET技术 ,  VC.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,