Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Movie title Year Revenue AliceInWonderland 2010 S 334191110 Avatar 2010 $ 408392

ID: 3713608 • Letter: M

Question

Movie title Year Revenue AliceInWonderland 2010 S 334191110 Avatar 2010 $ 408392727 Avengers :AgeofUltron 2015 $1405413868 DespicableMe 2010 $ 251203225 Furious7 2015 $1516045911 HarryPotterAndThe DeathlyHallows PartI 2010 $ 283533215 HowToTrainYourDragon 2010 217581231 Inception 2010 $ 292568851 InsideOut 2015 S 857611174 I ronMan2 2010 312433331 JurassicWorld 2015 $1670400637 Minions 2015 $1159398397 Mission: ImpossibletRogueNation 2015 S 682330139 ShrekForeverAfter 2010 238736787 Spectre 2015 $ 880674609 StarWars :TheForceAwakens 2015 $2068223624 TheHungerGames Mockingjay 2015 653428261 TheMartian 2015 630161890 TheTwilightSagaEclipse 2010 S 300531751 oyStory3 2010 415004880 Enter a movie title: Avatarr Title: Avatar ear Released 2010 Revenue $408392727 Do you want to continue? y/n>

Explanation / Answer

Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you


hw5functions.h
----------------
#ifndef hw5functions_h
#define hw5functions_h
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;

struct Movie
{
string title;
int yearReleased;
long revenue;
};

void storeMoviesArray(ifstream &inFile, Movie topMovies[], const int SIZE) // This function receives the input file, the movies array, and the size of the // array. // It reads from the file the movie data and stores it in the array. // Once all the data has been read in, it returns the array with the information // of the movies.
{
for(int i = 0; i < SIZE; i++)
{
inFile >> topMovies[i].title >> topMovies[i].yearReleased >> topMovies[i].revenue;
}

}
void sortMoviesTitle(Movie topMovies[], const int SIZE) // This function receives the movies array and the size of the array and sorts // the array by title. It returns the sorted array.
{
int i, j, minIdx;
Movie temp;
for(i = 0; i < SIZE; i++)
{
minIdx = i;
for(j = i +1; j < SIZE; j++)
{
if(topMovies[j].title < topMovies[minIdx].title)
minIdx = j;
}
if(i != minIdx)
{
temp = topMovies[i];
topMovies[i] = topMovies[minIdx];
topMovies[minIdx] = temp;
}
}

}

void printMoviesArray(Movie topMovies[], const int SIZE) // This function receives the movies array and the size of the array and prints // the list of movies.

{
cout << setw(50) << "Movie title" << setw(7) << "Year" << setw(12) << "Revenue" << endl;
for(int i = 0; i < SIZE; i++)
cout << setw(50) << topMovies[i].title << setw(7) << topMovies[i].yearReleased << " $" << setw(10) << topMovies[i].revenue << endl;

cout << endl;

}
int findMovieTitle(Movie topMovies[],const int SIZE, string title) // This function receives the movies array, the size of the array, and the title // of the movie to be searched for. // It returns the index of the array where the title was found. If the title was // not found, it returns -1.
{
int first = 0, last = SIZE - 1;
int mid;

while(first <= last)
{
mid = (first + last)/2;
if(topMovies[mid].title == title)
return mid;
else if(topMovies[mid].title > title)
last = mid -1;
else
first = mid + 1;
}

return -1;

}


#endif /* hw5functions_h */

main.cpp
--------
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include "hw5functions.h"
using namespace std;


int main()
{
const int SIZE = 3;
Movie topMovies[SIZE];
string filename = "movies.txt";
ifstream infile(filename.c_str());
string title;
string ans;

if(infile.fail())
{
cout << "ERROR: could not open input file " << filename << endl;
return 1;
}

storeMoviesArray(infile, topMovies, SIZE);
sortMoviesTitle(topMovies, SIZE);
printMoviesArray(topMovies, SIZE);

do
{
cout << "Enter a movie title: ";
cin >> title;
int index = findMovieTitle(topMovies, SIZE, title);
if(index == -1)
cout << endl << title << " not found" << endl;
else
{
cout << endl << "Title: " << topMovies[index].title << endl;
cout << "Year released: " << topMovies[index].yearReleased << endl;
cout << "Revenue: $" << topMovies[index].revenue << endl;

}

cout << endl << "Do you want to continue y/n ? ";
cin >> ans;
}while(ans == "y" || ans == "Y");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote