| | |
Structure help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
Here's the problem, questions at the bottom.
Write a program that uses a structure named MovieData to store the following information about a movie:
Title
Director
Year Released
Running time (in minutes)
Include a constructor that allows all 4 of these member data values to be specified at the time a MovieData variable is created. The program should create two MovieData variables and pass each one, in turn, to a function that displays the information about the movie in a clearly formatted manner.
I'm given
I've got a question right here. movie1 and movie2 are both variables no?(Cannot find an example of this in my book) It looks like a function there being parenthesis. How does it work?
what my structure looks like right now
My display message function
Am I along the right tracks or am I doing something totally wrong? I missed class this week and so I'm having a hard time grasping what I'm supposed to do. What am I doing wrong and what do i need to do to get this running. I've been messing around and looking through my book to understand how it works and no luck so far. Hints would be helpful
Write a program that uses a structure named MovieData to store the following information about a movie:
Title
Director
Year Released
Running time (in minutes)
Include a constructor that allows all 4 of these member data values to be specified at the time a MovieData variable is created. The program should create two MovieData variables and pass each one, in turn, to a function that displays the information about the movie in a clearly formatted manner.
I'm given
C++ Syntax (Toggle Plain Text)
// Chapter 7 - Assignment 1, Movie Data // This program stores movie information in a structure. // The structure is passed to a function to display the data. #include <iostream> #include <string> using namespace std; // -------------------------------- // ----- ENTER YOUR CODE HERE ----- // -------------------------------- // -------------------------------- // --------- END USER CODE -------- // -------------------------------- int main() { MovieData movie1("War of the Worlds", "Byron Haskin", 1953, 88), movie2("War of the Worlds", "Stephen Spielberg", 2005, 118); displayMovie(movie1); displayMovie(movie2); return 0; }
I've got a question right here. movie1 and movie2 are both variables no?(Cannot find an example of this in my book) It looks like a function there being parenthesis. How does it work?
what my structure looks like right now
C++ Syntax (Toggle Plain Text)
struct MovieData { string title, director; int year, time; MovieData(string t, string d, int y, int t2) { title = t, director = d, year = y, time = t2; } };
My display message function
C++ Syntax (Toggle Plain Text)
void displayMovie() { string title, director; int year, time; cout << "Title : " << title << endl; cout << "Director : " << director << endl; cout << "Year Released: " << year << endl; cout << "Running time : " << time << endl; }
Am I along the right tracks or am I doing something totally wrong? I missed class this week and so I'm having a hard time grasping what I'm supposed to do. What am I doing wrong and what do i need to do to get this running. I've been messing around and looking through my book to understand how it works and no luck so far. Hints would be helpful
Last edited by Foe89; Nov 16th, 2008 at 11:46 pm.
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
Found a problem, and now it's executable code. Still has problems though. The year/time is showing up as negative eighty thousands and the director/title are blank. two warnings with the year and time variables not getting initialized so theres something wrong with the movie1/2 values reaching the displayMovie function.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; struct MovieData { string title, director; int year, time; MovieData(string t, string d, int y, int t2) { title = t, director = d, year = y, time = t2; } }; void displayMovie(MovieData) { string title, director; int year, time; cout << "Title : " << title << endl; cout << "Director : " << director << endl; cout << "Year Released: " << year << endl; cout << "Running time : " << time << " minutes" << endl; } int main() { MovieData movie1("War of the Worlds", "Byron Haskin", 1953, 88), movie2("War of the Worlds", "Stephen Spielberg", 2005, 118); displayMovie(movie1); displayMovie(movie2); return 0; }
Last edited by Foe89; Nov 17th, 2008 at 12:34 am.
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
Nobody? I've got it where it displays
Title :
Director :
Year Released: -858993460
Running time : -858993460 minutes
Title :
Director :
Year Released: -858993460
Running time : -858993460 minutes
Press any key to continue
and I have no idea why the variables aren't being included
Title :
Director :
Year Released: -858993460
Running time : -858993460 minutes
Title :
Director :
Year Released: -858993460
Running time : -858993460 minutes
Press any key to continue
and I have no idea why the variables aren't being included
Last edited by Foe89; Nov 17th, 2008 at 1:20 am.
•
•
Join Date: Jul 2005
Posts: 1,681
Reputation:
Solved Threads: 264
you don't initialize title etc before outputting the variable so they have random, junk values. You don't need them anway. You want to use the dot operator to output the appropriate member variables of the object you sent to the function. You also need to give the function definition the name of the MovieData object it is going to use, not just the type, just like you do if you use a prototype before main() and define the function after main().
Klatu Barada Nikto
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
•
•
•
•
you don't initialize title etc before outputting the variable so they have random, junk values. You don't need them anway. You want to use the dot operator to output the appropriate member variables of the object you sent to the function. You also need to give the function definition the name of the MovieData object it is going to use, not just the type, just like you do if you use a prototype before main() and define the function after main().
And about the function definition data type. With the setup I have to use, the data type is both string and int values that are in the movie1/2 parenthesis, no?
•
•
Join Date: Jul 2005
Posts: 1,681
Reputation:
Solved Threads: 264
>>the data type is both string and int values that are in the movie1/2 parenthesis
fine.
fine.
C++ Syntax (Toggle Plain Text)
void displayMovie(MovieData & md) { cout << "Title : " << md.title << endl; }
Klatu Barada Nikto
![]() |
Similar Threads
- Discrete Math or Data structure (Computer Science)
- Can array works within Structure? (C)
- Structure Help Please (C++)
- Question regarding correct table structure (HTML and CSS)
- Scandisc stops at "File Structure" (Windows 95 / 98 / Me)
Other Threads in the C++ Forum
- Previous Thread: error dynamic_cast in c++
- Next Thread: hw help!! struct + arrays + formatting
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






