Output Giving Garbage Value

Below i am pasting a source code of c++ program,My source code has to do simple input and out put operations on classes but when i compile the program class book output is coming right but class tape out put is not correct plz kindly help me in solving this.Below is code..

// publication.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#define MAX 30
using namespace std;
class publication
{
private:
char title[MAX];
float price;
public:
publication(){}
publication(char t[],float p):price(p){title[0]='\0';}
void readata()
{
cout<<"Enter The Title";
cin.get(title,MAX);
cout<<"Enter The Price";
cin>>price;
}
void display()
{
cout<<"Entered Title"<<title<<endl;
cout<<"Enter Price"<<price<<endl;
}
};
class book:public publication
{
protected:
int pages;
public:
book(char t[],float p,int pg):publication(t,p),pages(pg){}
void readata()
{
publication::readata();
cout<<"Enter The # of pages";
cin>>pages;
}
void display()
{
publication::display();
cout<<"Entered # of pages"<<pages;
}
};
class tape:public publication
{
protected:
int length;
public:
tape(char t[],float p,int l):publication(t,p),length(l){}
void readata()
{
publication::readata();
cout<<"Enter length of play";
cin>>length;
}
void display()
{
publication::display();
cout<<"Length of play"<<length;
}
};
void main()
{
book b1;
tape t1;
cout<<"Enter Book Details :"<<endl;
b1.readata();
cout<<"Details of Book are "<<endl;
b1.display();
cout<<"Enter Details of tape "<<endl;
t1.readata();
cout<<"Entered Details of tape are "<<endl;
t1.display();
system("pause");
}
Last edited on
Your code does not compile, please fix it.
main.cpp:61:11: error: ‘::main’ must return ‘int’
main.cpp:63:7: error: no matching function for call to ‘book::book()’
main.cpp:64:7: error: no matching function for call to ‘tape::tape()’
main.cpp:73:16: error: ‘system’ was not declared in this scope


> but class tape output is not correct
be more specific. ¿what output do you expect? ¿what are you getting? ¿which test data are you using?
Please try to recompile the code it runs perfectly in Microsoft Visual studio 2008 ....in this program i am just giving the input through the keyboard and getting the output on screen but....when i give input for tape object that gives output which contains garbage value.......
Please try to recompile the code it runs perfectly in Microsoft Visual studio 2008

That doesn't mean it's correct, because it most certainly isn't.
It's known that VC allows void main(), but I find it rather difficult to believe that it would allow you to use constructors that simply don't exist. Either way - it's wrong, so fix it.
Just compiled for VS 2008 and...

Error 3 error C2512: 'book' : no appropriate default constructor available main.cpp 66
Error 4 error C2512: 'tape' : no appropriate default constructor available main.cpp 67
firedraco@ Kindly assist me in the making of constructors in it.....what type of constructor should i use in it...please kindly correct my code and paste here.
If there is error in constructor then help me to solve it.....if i could solve it then i would not asked here......
Your default constructors for book and tape are missing, it's as simple as that. Just add them.
Topic archived. No new replies allowed.