I have wirtten the program , it executes but the only error it has is that when I run this program it is not proceeding further after entering a required data (some type of logical error :'( )
[
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
class publication
{
private:
string title;
float price;
public:
void getdata()
{
cout<<"Title:";getline(cin,title,' ');
cout<<"Price:";cin>>price;
}
void putdata()
{
cout<<"Title is=" <<title<<endl;
cout<<"Price is=" <<price<<endl;
}
};
class book:public publication
{
private:
int count;
public:
void getdata()
{
publication::getdata();
cout<<"Count:";cin>>count;
}
void putdata()
{
publication::putdata();
cout<<"Count is=" <<count<<endl;
}
};
class tape:public publication
{
private:
float playingtime;
public:
void getdata()
{
publication::getdata();
cout<<"Playing time:";cin>>playingtime;
}
void putdata()
{
publication::putdata();
cout<<"Playing time=" <<playingtime<<endl;
}
};
void main()
{
book b1;
tape t1;

b1.getdata();
b1.putdata();
t1.getdata();
t1.putdata();
}
]

Comments
What it also needs is someone who can read intro threads, and can figure out what code tags are, more than just [ basically.

...]

in the publication class, there is a line uses

getline function in a wrong logic.

getline(cin,title,' ');

HEre the input is taken till a space is seen, but we have to press enter to end the input.
ex. if you type "mytitle " and press enter, it continues.
but if you type "mytitle" with no space, it still looks for a space char.

so, I think you should not use getline.
but if you have, use it like that

getline(cin,title,'\n');

so you can get line till the enter is pressed.

but there will be another problem now. buffered characters will pass the input streams.
you can avoid if by usinf fflush(stdin); after each cin >> ..
but it is deprecated
...

This article has been dead for over six months. Start a new discussion instead.