Question

Write a C++ program that uses a structure named Movie to store the following. a. Title b. Director c. Year Released d. Runnin

of size 3. Movie getData(); In the function getData() will prompt for user to enter the data for each of the elements shown a

c++ if you answer the question please write it line by line and not in paragrapth form.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CONCEPT..:

SINCE STRUCT IS TOOL TO COMBINE LOT OF DATAS TOGETHER... LIKE STRING INT FLOAT..ETC..

CALL BY REFRENCE IS USED FOR ACCESSING ORIGINAL VALUES DURING FUNCTION CALL ..OTHERWISE

CALL BY VALUE MAKES DUPLICATE VARIABLES AND WORK ON THEM SO NO CHANGE IN ORIGINAL VALUES..

//CODE SOLUTION:

#include <iostream>
using namespace std;

// declartion of the struct for all the variables of the movie ..
//struct is used to combine all the variables together...

struct movie
{   
//all the variables such as movie and director year combined together..
string Title;
string director;
string year_of_release;
int running_time;
double cost_of_production;
double revenue;
  
  
//Note here i have
take title as string ..
//director as string .. and cost_of_production
// as double you can take any type if you want..
};


struct movie getData()
//this is a function to take input of the values fromm the user .. std... input

{

struct movie m1;
cout<<"Enter the Title of the movie\n";
cin>>m1.Title;
cout<<"Enter the director of the movie\n";
cin>>m1.director;
cout<<"Enter the year_of_release\n";
cin>>m1.year_of_release;
cout<<"Enter the running_time of the movie(in minutes.)\n";
cin>>m1.running_time;
cout<<"Enter the cost_of_production \n";
cin>>m1.cost_of_production;
cout<<"Enter the revenue of the movie \n";
cin>>m1.revenue;
  
return m1;
  
//we use dot operator here in order to find out input the values...

}


void printData(struct movie *m1)
//this is a function to show output.. of the values fromm the user .. std... output..

{
cout<<"The Title of the movie: "<<m1->Title<<"\n";
cout<<"The director of the movie: "<<m1->director<<"\n";
cout<<"The year_of_release of the movie: "<<m1->year_of_release<<"\n";
cout<<"The running_time of the movie: "<<m1->running_time<<"minutes"<<"\n";
cout<<"The cost_of_production of the movie: "<<m1->cost_of_production<<"\n";
cout<<"The revenue of the movie: "<<m1->revenue<<"\n";
  
double profit,loss;
  
if(m1->cost_of_production>m1->revenue)
{
cout<<"loss in the movie: "<<m1->cost_of_production-m1->revenue<<"\n";
}
  
else
{
cout<<"profit in the movie is: "<<m1->revenue-m1->cost_of_production<<"\n";
  
}
  
  
  
//Note in this function we have used call by refrence.. to access the data.. to original
//variable so since m1 is of pointer type so we have used the (->)of variable here..
//return type is also pointer of type struct here..
  
}

int main() {
  
struct movie m1[3];

for(int i=0; i<3; i++)
{
m1[i]=getData(); //call by value to get the data to our array..
}
  
  
//call the function by refrence to output the data...
  
for(int i=0; i<3; i++)
{
  
printData(&m1[i]); //we have used call by refrence here in this function to output
//values to fromm m1 variable
  
  
}
  

   return 0;
}


INPUT IS:

hero
sks
2016
124
45.56
124.40
swaha
srisanth
2017
100
70.567
56.40
jago
amit
2019
90
80.56
300.456

OUTPUT IS:

Enter the Title of the movie
Enter the director of the movie
Enter the year_of_release
Enter the running_time of the movie(in minutes.)
Enter the cost_of_production
Enter the revenue of the movie
Enter the Title of the movie
Enter the director of the movie
Enter the year_of_release
Enter the running_time of the movie(in minutes.)
Enter the cost_of_production
Enter the revenue of the movie
Enter the Title of the movie
Enter the director of the movie
Enter the year_of_release
Enter the running_time of the movie(in minutes.)
Enter the cost_of_production
Enter the revenue of the movie
The Title of the movie: hero
The director of the movie: sks
The year_of_release of the movie: 2016
The running_time of the movie: 124minutes
The cost_of_production of the movie: 45.56
The revenue of the movie: 124.4
profit in the movie is: 78.84
The Title of the movie: swaha
The director of the movie: srisanth
The year_of_release of the movie: 2017
The running_time of the movie: 100minutes
The cost_of_production of the movie: 70.567
The revenue of the movie: 56.4
loss in the movie: 14.167
The Title of the movie: jago
The director of the movie: amit
The year_of_release of the movie: 2019
The running_time of the movie: 90minutes
The cost_of_production of the movie: 80.56
The revenue of the movie: 300.456
profit in the movie is: 219.896

SCREENSHOHOT OF INPUT AND OUTPUT..

3 29 30 31 32 33 34 35 36 37 38 39 3 3 struct movie ml; cout<<Enter the title of the movie\n; cin>>ml.Title; cout<<Enter t

SCREENSHOT OF CODE HERE.

C++14 (Gcc 6.3) Code gets autosaved every second 1 #include <iostream> 2 using namespace std; 3 4 // declartion of the struct28 29 struct movie ml; 30 cout<<Enter the title of the movie\n; 31 cin>>ml.Title; 32 cout<<Enter the director of the movie.com/de C++14 (Gcc 6.3) Code gets autosaved every second { } } 66 67 68 else 69 70 cout<<profit in the movie is: <<ml->reve

Add a comment
Know the answer?
Add Answer to:
c++ if you answer the question please write it line by line and not in paragrapth...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • write a C++ program that uses a class named Movie to store the following information about...

    write a C++ program that uses a class named Movie to store the following information about a movie: - Title - Director - Year Released - Running time (in minutes) + print() : Function that will print the information for this movie in a nice format Include a constructor that allows all four of these member data values to be specified at the time a Movie variable is created. The program should create four Movie variables and call its print()...

  • C++ Checkpoint 11.33 Look at the following structure definition: struct Date int month int day int year, Write the pr...

    C++ Checkpoint 11.33 Look at the following structure definition: struct Date int month int day int year, Write the prototype for a function called getlnput that accepts a pointer to a Date structure as a parameter. Type your program submission here. Checkpoint 11.28 Look at the following structure definition struct Rectangle int length int width Write the definition of a pointer to a Rectangle structure called rectPtr and assign it the value nullptr Fype your progzam submission heze

  • C++ 29.5 Lab 29: Pointers Exercise: Before the main function, declare a struct called Movie which...

    C++ 29.5 Lab 29: Pointers Exercise: Before the main function, declare a struct called Movie which has title as a string and year as the integer as the member variables. Also before the main function, instantiate an object of Movie called m with initial value "Avengers" as title and year as 2019. Note m is the global variable and A in the title is uppercase. Also before the main function, declare another global variable which is a pointer to the...

  • C++Write a program that uses a class name MovieData to store the following information about a...

    C++Write a program that uses a class name MovieData to store the following information about a movie: create a class not a strcuture please. Title Director Year release Running time Inclue a constructor that allows all four of these memberdata values to be sprcified at the time a MovieData variable is created The program should create two MovieData variable. Do not use user input. Have a stand alone function that displays the information about the movie in a clearly formatted...

  • Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as...

    Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as follows: If you did not complete A8, you will need to start with those instructions, and then, change your code based on the instructions here The main() function should: Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...) Concerning the function call for getData(), pass the address of the array and its size to pointers; depending on...

  • Write a main program that will randomly fill a 2 dimensional array with integer values in...

    Write a main program that will randomly fill a 2 dimensional array with integer values in the range of 0 to 50. Use the Rand_Int function and constants to do this. These values represent the height of a terrain. Write a function that will determine what part of the terrain will flood. A. Create a global constant called MAX and assign it the value of 10. B. Prompt the user in main, at what height do they consider it to...

  • Project Description: In this project, you will combine the work you’ve done in previous assignments to...

    Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...

  • PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class...

    PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...

  • Need this in C++ Goals: Your task is to implement a binary search tree of linked...

    Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT