Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Apr 2002
Posts: 212
Member
Member
Joined: Apr 2002
Posts: 212
Just trying to store movie title, year, rating.

here's my code...

Code
#include <iostream>
#include <cstdio>
using namespace std;

class Movie
{
    public:
    	Movie(char title, int year, int rating);	
	void print();
    
    private:
      char m_title;
    	int m_year;
    	int m_rating;
};

Movie::Movie(char title, int year, int rating)
{
    m_year = year;
    m_rating = rating;
    m_title = title;
}

void
Movie::print()
{
    cout << "Year: " << m_year << "," << m_title << ", rating = " << m_rating << endl;
}


int
main()
{
    Movie *data[100];	// array to hold the dynamically created Pair objects
    int num_movies = 0;	// the number of pair objects we have created
    char *title;
    int year, rating;		// hold values read from cin

    // as long as there is an integer to read, read it (as long as not EOF)
    while (cin >> title) 
    gets(title);
    {
	//read 2nd integer in pair (dangerous assumption, what if no more nums?)
        cin >> year; 
        
        //
        cin >> rating;

	// instantiate a new Pair object using the new operator
	data[num_movies] = new Movie(*title, year, rating);

	// we have read another pair of integers, update our counter
	num_movies++;  
    }

    // print out all the pairs pointed to by the data array
    for (int i = 0; i < num_movies; i++)
    {
    	cout << i << endl;
    	data[i]->print();
    }

}
after i compile and run i'm getting crazy output like this:

year: -3242342 , rating = -12342354

won't dispaly the title at all and give me crazy output like that. Any ideas on what I'm doing wrong here?

thanks

Sponsored Links
▼ Sponsored Links ▼ ▲ Sponsored Links ▲
Joined: Mar 2002
Posts: 93
Junior Member
Junior Member
Joined: Mar 2002
Posts: 93
First of all, your class has a litle mistake.

the char title;
shoulde be char *title;
this because you know hold a single char.

So, I supose that this maybe [censored] it.
Try it out, also do some controlls by adding some few lines like;

cout << title << endl;

just before reading data with

cin >> year;

try that.
wink


- "It's not my code that's useless
it's you loosers being unable to
apprecitate it because of your
lack of skills!"
/zenon - C++ master Apprentice

Link Copied to Clipboard
Member Spotlight
None yet
Forum Statistics
Forums41
Topics33,840
Posts68,858
Members2,176
Most Online3,253
Jan 13th, 2020
Latest Postings
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
Girlie 1
unreal 1
Crime 1
Ice 1
Dartur 1
Powered by UBB.threads™ PHP Forum Software 8.0.0