help with some c++ compiling errors

Discussion in 'OT Technology' started by MP, Sep 16, 2004.

  1. MP

    MP New Member

    Joined:
    Sep 10, 2002
    Messages:
    34,377
    Likes Received:
    0
    Location:
    Silicon Valley
    Trying to make a simple movie database. All it has to do is store the title, year, and rating.

    to start things off, here is my code...
    Code:
    /*
    
    
    */
    
    #include <iostream>
    using namespace std;
    
    class movie
    {
        // Setting the field variables
        string title;
        string year;
        int rating;
      
        public:
        // Define the constructors
        movie() { title = ""; year = ""; }
        movie(int rating)
        movie(string m_title, string m_year; int m_rating)
        {
            title = m_title;
            year = m_year;
            rating = m_rating;
        } 
       
        // Define the mutators
        void settitle(string m_title)  	{ title = m_title; }
        void setyear(string m_year)	 	{ year = m_year; }
        void setrating(int m_rating)	{ rating = m_rating; }
        
        //Define the accessors...
        string gettitle()	 		{ return title; }
        string getyear() 			{ return year; }
        int getrating()		 	{ return rating; }
        
    };
    
    
    // Declare functions...
    void add(movie newmovie, movie movielist[], int&);
    void print(movie, int);
    
    int main()
    
    {
       int currsize = 0;
       string m_title, m_year;
       int m_rating;
       
       movie tempmovie;
       movie list[100];
       
       //This is the main processor loop that drives the operation
       //of the program...
       
       for( ; ; ) 
        {
            add();
            cout << "go";
            getline(cin);
         
            if(currsize == 100)
            break;
            else if(add)
        {
            cout << "Title: " << endl;
            getline(cin, m_title);
            cout << "Year: ";
            getline(cin, m_title);
            cout << "Rating: ";
            getline(cin, m_rating);
            
            tempmovie.settitle(m_title);
            tempmovie.setyear(m_year);
            tempmovie.setrating(m_rating);
            
            add(tempmovie, list, currsize);
        }
    
        do(print)
        print(movielist, currsize);
        
        }
        
        cout << "Thank you, come again" << endl;
    
    }  
    
    //add() will allow the user to put a new value on the list.
    void add(movie newmovie, movie movielist[], int& currsize)
    {
        if(currsize < 100) 
        {
            movielist[currsize] = newmovie;  //put the name on the end...
            currsize++;
        }
        else
        cout << "Sorry, List is full!" << endl;
    }
    
    //print() will display all the names on the list...
    
    void print(movie movielist[], int currsize)
    {
        int k;
       
        for(k = 0 ; k < currsize ; k++)
        if(movielist[k].getyear() != "") 
        {
            cout << "Year: " << k << "" << movielist[k].getyear();
            cout << " " << movielist[k].gettitle();
            cout << ", Rating = " << movielist[k].getrating() << endl;
        }
    }
    
    I keep getting these errors...

    movie.cpp:24: error: parse error in method specification before `(' token
    movie.cpp:41: error: parse error before `}' token
    movie.cpp:96: error: `void movie::add(movie, movie*, int&)' and `void
    movie::add(movie, movie*, int&)' cannot be overloaded
    movie.cpp:119: error: parse error at end of input

    i'm not sure what's going on with the parse errors really. I looked over it but don't know what is wrong. As faras the error on line 96 :dunno:


    any suggestions wouldbe helpfull

    thanks
     
  2. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    Couple of things:

    1.) When you declare a class, usually declare the class in a header file and write the code for the constructors and member functions in a cpp file.

    2.) When you call add() right after the start of your main loop, you give it no arguments! You just declared it up above with 3 arguments.

    3.) Your getline calls are messed up. Call it like this:
    cin.getline(buf, buflength); Where buf is a array of chars, and buflength is the length of that array. The instantiate a new string using the characters read in as the constructor argument.

    4.) For m_rating, you'll need to use m_rating = atoi(buf) after reading that value from cin

    That should get you started in the right direction.
     
  3. MP

    MP New Member

    Joined:
    Sep 10, 2002
    Messages:
    34,377
    Likes Received:
    0
    Location:
    Silicon Valley
    1: yeah, I was trying to get it all to work in one big file before I split it up. I've never done c++ with multiple files (as you can probably tell)

    2: wewps, didn't even notice that

    3: buf and buflength? damn i've never even heard of that :hs:

    4: what's atoi(buf) ?

    thanks though, the first two solutions i'll start on and I'll get on the second two as soon as I learn more about buf

    thanks again
     

Share This Page