Homework Help
Jul 7, 2014 at 1:31pm UTC
Hello, I was working on my C++ homework and was wondering if anyone could help me with part of it. I wrote the .cpp and .h files but now I am stuck. Here is what I am supposed to do:
1. Write a subprogram (not a method) void promptForMovie(Movie & myMovie); that prompts the user for movie information, and returns a Movie object to the calling program. When this command is executed, the user will be asked to supply the attributes for the movie.
2. Write a method void output(ostream & out); that will display movie information as follows:
Movie:
Director:
Year:
Rating:
IMDB URL:
Here is my header file: MovieClass.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
// This is the header file that includes the interface of the Movie class
#ifndef _MOVIE_
#define _MOVIE_
#include <string>
using namespace std;
enum Movie_Rating {G,PG,PG13,R,NC17,NR} ;
class Movie
{
public : // interface of the Socialite_user class
//------------ Constructors ------------------
Movie();
Movie(const string& title) ;
Movie(const string& title,
const string& director,
Movie_Rating rating,
unsigned int year,
const string& path) ;
// ------------------------------------------------------
// ----- Destructor -------------------------------------
// ------------------------------------------------------
// ~Movie(); // To be implemented in a future assignment.
//------------ Inspectors --------------------
string getTitle() const ;
string getDirector() const ;
Movie_Rating getRating() const ;
unsigned int getYear() const ;
string getURL() const ;
//------------ Mutators ---------------------
void setTitle(const string& title);
void setDirector(const string& director) ;
void setRating(Movie_Rating rating) ;
void setYear(unsigned int year) ;
void setURL(const string& path) ;
private : // private data fields associated with Socialite_user objects
// Underscores indicate a private member variable
string title_ ;
string director_ ;
Movie_Rating rating_ ;
unsigned int year_ ;
string url_ ;
};
#endif
MovieClass.cpp :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
// This is the file that includes the implementation of the Movie class
#include "MovieClass.h"
#include <string>
#include <cstdlib>
#include <ciso646>
#include <sstream>
using namespace std;
//-----------Constructors-----------------
Movie::Movie()
{
title_ = "" ;
director_ = "" ;
url_ = "" ;
rating_;
year_;
}
Movie::Movie(const string& title)
{
title_ = "" ;
}
Movie::Movie(const string& title, const string& director, Movie_Rating rating, unsigned int year, const string& path)
{
title_ = "" ;
director_ = "" ;
url_ = "" ;
rating_;
year_;
}
//---------------Inspectors--------------------------
string Movie::getTitle() const
{
return title_;
}
string Movie::getDirector() const
{
return director_;
}
Movie_Rating Movie::getRating() const
{
return rating_;
}
unsigned int Movie::getYear() const
{
return year_;
}
string Movie::getURL() const
{
return url_;
}
//--------------------Mutators-------------------
void Movie::setDirector(const string& director)
{
director_ = director;
}
void Movie::setRating(Movie_Rating rating)
{
rating_ = rating;
}
void Movie::setYear(unsigned int year)
{
year_ = year;
}
void Movie::setURL(const string& path)
{
url_ = path;
}
And this is supposed to be my test file; I am pretty sure I wrote this completely wrong. I think this is where I would put the subprogram and method they are asking for?: main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
// This is the file that will test the implementation of the MovieClass
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include "MovieClass.h"
using namespace std;
//------------------------------------------------------
// Prints out Movie Information
//------------------------------------------------------
void output(ostream & out);
int main(void )
{
Movie promptForMovie;
cout << "Movie: " << Movie.setTitle << endl;
cout << "Director: " << Movie.setDirector << endl;
cout << "Year: " << Movie.setYear << endl;
cout << "Rating: " << Movie.setRating << endl;
cout << "IMDB URL: " << Movie.setURL << endl;
ofstream myfile;
myfile.open ("MovieTest.txt" );
myfile << "Movie: " ;
myfile << promptForMovie.getTitle();
myfile << "\n" ;
myfile << "Director: " ;
myfile << promptForMovie.getDirector();
myfile << "\n" ;
myfile << "Year: " ;
myfile << promptForMovie.getYear();
myfile << "\n" ;
myfile << "Rating: " ;
myfile << promptForMovie.getRating();
myfile << "\n" ;
myfile << "IMDB Url: " ;
myfile << promptForMovie.getURL();
myfile << "\n" ;
myfile.close();
return 0;
}
Thank you
Jul 7, 2014 at 1:44pm UTC
First error that i can see is:
1 2 3 4 5
cout << "Movie: " << Movie.setTitle << endl;
cout << "Director: " << Movie.setDirector << endl;
cout << "Year: " << Movie.setYear << endl;
cout << "Rating: " << Movie.setRating << endl;
cout << "IMDB URL: " << Movie.setURL << endl;
the bracket are missing and i suppose you wanted to call the getTitle, getDirector ecc... Or you should call the setters with the cin operator...
Jul 7, 2014 at 2:11pm UTC
Yea I'm pretty sure that whole section is wrong. I want to prompt the user for this information and then call it so I can output the information. How would I write a subprogram that would do that?
Jul 7, 2014 at 2:58pm UTC
So for the console prompt part it should be:
1 2 3 4 5
cout << "Movie: " << promptForMovie.getTitle() << endl;
cout << "Director: " << promptForMovie.getDirector() << endl;
cout << "Year: " << promptForMovie.getYear() << endl;
cout << "Rating: " << promptForMovie.getRating() << endl;
cout << "IMDB URL: " << promptForMovie.getURL() << endl;
in this way your program will write in the console that attibutes, but you need to insert some values. So before that you should write:
1 2 3 4
cout << " Insert Movie: " << endl;
string tempString;
cin >> tempString;
promptForMovie.setTitle(tempString);
and so on for all the data you wanna insert.
Jul 7, 2014 at 4:46pm UTC
Thanks! Now how would I write a method void output(ostream & out); that will display movie information?
Topic archived. No new replies allowed.