| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3800 人关注过本帖
标题:为什么不能输入标题??
只看楼主 加入收藏
winnie96
Rank: 2
等 级:论坛游民
帖 子:51
专家分:86
注 册:2015-12-14
结帖率:53.85%
收藏
已结贴  问题点数:20 回复次数:1 
为什么不能输入标题??
#include<iostream>
#include<string>
using namespace std;
class Publication{
    protected:
        string title;
        float price;
    public:
        Publication(string ti,float pri):title(ti),price(pri)
        {
        
        }
        void GetData(){
            string tit;
            float pri;
            cout<<"输入标题:"<<endl;
            getline(cin,tit);
            
            cout<<"输入价格"<<endl;
            cin>>pri;
            Settitle(tit);
            Set_price(pri);   
            
        }
        void Settitle(string ti){
            title=ti;
            
        }
        void Set_price(float pri){price=pri;
        }
        void Show(){
            cout<<"标题:"<<title<<endl;
            cout<<"价格:"<<price<<"元"<<endl;
        }
        ~Publication(){
        }
};
class Book:public Publication
{
    protected:
        int page;
    public:
        Book(string ti="",float pri=0,int pa=0):Publication(ti,pri),page(pa){
        }
        
        void GetData(){
            Publication::GetData();
            cout<<"输入页数:"<<endl;
            int pa;
            cin>>pa;
            Set_page(pa);            
        }
        void Set_page(int pa){
            page=pa;
        }
        void Show(){
            Publication::Show();
            cout<<"页数:"<<page<<"页"<<endl;
        }
        ~Book(){
        }
};
class Tape:public Publication
{
    protected:
        float playtime;
    public:
        Tape(string ti="",float pri=0,float playt=0):Publication(ti,pri),playtime(playt){
        }
        void GetData(){
            Publication::GetData();
            cout<<"输入播放时间:"<<endl;
            float playt;
            cin>>playt;
            playtime=playt;
        }
        void Show(){
            Publication::Show();
            cout<<"播放时间:"<<playtime<<"分钟"<<endl;
        }
};
 
int main(){
    cout<<"建立书籍"<<endl;
    Book b1;
    string str;
    b1.GetData();
    b1.Show();
//    cout<<"重新输入标题:"<<endl;     //有问题,不能重新输入标题
   
//    getline(cin,str);
//    b1.Settitle(str);
//    b1.Show();
   
    cout<<"建立磁带"<<endl;//也不能输入标题
    Tape t1;
    t1.GetData();
    t1.Show();
    return 0;
}
搜索更多相关主题的帖子: title price public include 
2016-04-13 19:11
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:20 
用cin>>行不行?
2016-04-14 12:22
快速回复:为什么不能输入标题??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016740 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved