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

c++ programming There is a file of a few movies that contains the following data

ID: 3883906 • Letter: C

Question

c++ programming

There is a file of a few movies that contains the following data:

Date of release
Movie name
Production cost
Gross profit

Your assignment is: for each movie,

1. Without changing the data, read in the Date of release,
      the Movie name, the Production cost and the Gross profit
      for all of the movies and put the information into an
      array of structs (or classes).
2. Sort the array of movies by Movie Name alphabetically
3. Print the array of movies with a heading.
      The fields should be printed in the following order:
      Movie Name, Release Date, Production cost and Gross profit
4. Sort the array of movies by Percent Profit (Gross profit/Production Cost)
3. Print the array of movies with a heading.
      The fields should be printed in the following order:
      Movie Name, Production cost, Release Date and Percent Profit

//input file

                                                                                                   11111

         11111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000

12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234

Release Date         Movie                                   Production Budget        Worldwide Box Office

Dec 15, 1939         Gone with the Wind                         $3,900,000                  $390,525,192

Jun 4, 1982          Poltergeist                               $10,700,000                  $121,706,019

Feb 9, 2001          Hannibal                                  $87,000,000                  $350,100,000

Mar 23, 2001         Heartbreakers                             $38,000,000                   $57,753,825

Aug 3, 2001          Original Sin                              $26,000,000                   $16,521,410

Jun 14, 2002         Windtalkers                              $115,000,000                   $77,628,265

Mar 14, 2003         Agent Cody Banks                          $25,000,000                   $58,240,458

Apr 15, 2005         The Amityville Horror                     $18,500,000                  $108,800,304

Mar 16, 2007         Premonition                               $20,000,000                   $81,461,343

Feb 22, 2008         Charlie Bartlett                          $12,000,000                    $5,295,909

Dec 25, 2008         Valkyrie                                  $90,000,000                  $203,902,107

Jun 12, 2009         The Taking of Pelham 123                 $110,000,000                  $152,364,370

Jul 8, 2011          Zookeeper                                 $80,000,000                  $170,805,525

Dec 20, 2011         The Girl with the Dragon Tattoo           $90,000,000                  $239,373,970

Mar 16, 2012         21 Jump Street                            $42,000,000                  $202,812,429

Aug 8, 2012          Hope Springs                              $30,000,000                  $115,849,781

Nov 8, 2012          Skyfall                                  $200,000,000                $1,110,526,981

Dec 14, 2012         The Hobbit: An Unexpected Journey        $250,000,000                $1,017,003,568

Jan 25, 2013         Hansel & Gretel: Witch Hunters            $50,000,000                  $214,949,716

Mar 27, 2013         G.I. Joe: Retaliation                    $140,000,000                  $371,923,060

Oct 18, 2013         Carrie                                    $30,000,000                   $82,409,520

Jun 13, 2014         22 Jump Street                            $50,000,000                  $331,333,876

Dec 17, 2014         The Hobbit: The Battle of the 5 Armies   $250,000,000                  $955,119,788

Feb 20, 2015         Hot Tub Time Machine 2                    $14,000,000                   $12,452,601

May 8, 2015          Hot Pursuit                               $35,000,000                   $45,680,201

                                                                                                   11111

         11111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000

12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234

Release Date         Movie                                   Production Budget        Worldwide Box Office

Dec 15, 1939         Gone with the Wind                         $3,900,000                  $390,525,192

Jun 4, 1982          Poltergeist                               $10,700,000                  $121,706,019

Feb 9, 2001          Hannibal                                  $87,000,000                  $350,100,000

Mar 23, 2001         Heartbreakers                             $38,000,000                   $57,753,825

Aug 3, 2001          Original Sin                              $26,000,000                   $16,521,410

Jun 14, 2002         Windtalkers                              $115,000,000                   $77,628,265

Mar 14, 2003         Agent Cody Banks                          $25,000,000                   $58,240,458

Apr 15, 2005         The Amityville Horror                     $18,500,000                  $108,800,304

Mar 16, 2007         Premonition                               $20,000,000                   $81,461,343

Feb 22, 2008         Charlie Bartlett                          $12,000,000                    $5,295,909

Dec 25, 2008         Valkyrie                                  $90,000,000                  $203,902,107

Jun 12, 2009         The Taking of Pelham 123                 $110,000,000                  $152,364,370

Jul 8, 2011          Zookeeper                                 $80,000,000                  $170,805,525

Dec 20, 2011         The Girl with the Dragon Tattoo           $90,000,000                  $239,373,970

Mar 16, 2012         21 Jump Street                            $42,000,000                  $202,812,429

Aug 8, 2012          Hope Springs                              $30,000,000                  $115,849,781

Nov 8, 2012          Skyfall                                  $200,000,000                $1,110,526,981

Dec 14, 2012         The Hobbit: An Unexpected Journey        $250,000,000                $1,017,003,568

Jan 25, 2013         Hansel & Gretel: Witch Hunters            $50,000,000                  $214,949,716

Mar 27, 2013         G.I. Joe: Retaliation                    $140,000,000                  $371,923,060

Oct 18, 2013         Carrie                                    $30,000,000                   $82,409,520

Jun 13, 2014         22 Jump Street                            $50,000,000                  $331,333,876

Dec 17, 2014         The Hobbit: The Battle of the 5 Armies   $250,000,000                  $955,119,788

Feb 20, 2015         Hot Tub Time Machine 2                    $14,000,000                   $12,452,601

May 8, 2015          Hot Pursuit                               $35,000,000                   $45,680,201

Explanation / Answer

//main.cpp


//program pairs with movie.file
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <iomanip>
using namespace std;

struct info {
string release;
string title;
string budget;
string box;
double b;
double bo;
};

void delete_chars(string & st, char ch) {

int i = st.find(ch);
while(i > -1) {
st.replace(i, 1, "");
i = st.find(ch);
}

}

int main() {
string st, re, tit;
string bud, bx;
int d, x;
info list[26];

//imports file into struct fields
for(int i = 0; i < 26; i++) {

getline(cin, st);

re = st.substr(0, 12);
tit = st.substr(20, 39);
bud = st.substr(60, 18);
bx = st.substr(85, 21);

delete_chars(bud, '$');
delete_chars(bud, ',');
delete_chars(bx, '$');
delete_chars(bx, ',');

list[i].release = re;
list[i].title = tit;
list[i].budget = bud;
list[i].box = bx;
}

cout << "The list of films unsorted" << endl;
cout << "-----------------------------------------------------------------------------------------" << endl;
cout << endl;

//prints the file from struct fields
for(int j = 0; j < 26; j++) {

cout << list[j].release << " " << list[j].title
<< " " << list[j].budget << " "
<< list[j].box << endl;
}

cout << "-----------------------------------------------------------------------------------------" << endl;

int size = 26;

//converts strings into floating point numbers
//and then copies values into another struct field
for(int f = 1 ; f < size; f++) {

list[f].b = atof(list[f].budget.c_str());
list[f].bo = atof(list[f].box.c_str());
}

//Sorts file by film title
int swaps = 1;
size = 26;

while(swaps) {

swaps = 0;

for(int x = 1; x < size - 1; x++) {

if(list[x].title > list[x + 1].title) {

swap(list[x], list[x + 1]);
swaps = 1;
}
}
}

//Prints sorted fields
cout << setprecision(2) << fixed;
cout << endl;
cout << "Sorted by title" << endl;
cout << "-----------------------------------------------------------------------------------------" << endl;
cout << endl;
cout << list[0]. title
<< setw(15) << right
<< list[0].release
<< setw(20) << right
<< list[0].budget
<< setw(15) << right
<< list[0].box << endl;
  
for(int y = 1; y < 26; y++) {

cout << list[y].title
<< setw(15) << right
<< list[y].release
<< setw(20) << right
<< list[y].b
<< setw(15) << right
<< list[y].bo << endl;
}   
  
cout << "-----------------------------------------------------------------------------------------" << endl;

//sorts fields by percent profit
swaps = 1;
  
while(swaps) {
  
  
swaps = 0;
  
for(int e = 1; e < size - 1; e++) {

if(list[e].bo / list[e].b < list[e + 1].bo / list[e + 1].b) {

swap(list[e], list[e + 1]);
swaps = 1;
}
}
}

//prints sorted fields
cout << endl;
cout << "Sorted by profit" << endl;
cout << "-----------------------------------------------------------------------------------------" << endl;
cout << endl;
cout << list[0]. title
<< setw(15) << right
<< list[0].release
<< setw(20) << right
<< list[0].budget
<< setw(15) << right
<< list[0].box << endl;

for(int y = 1; y < 26; y++) {

cout << list[y].title
<< setw(15) << right
<< list[y].release
<< setw(20) << right
<< list[y].b
<< setw(15) << right
<< list[y].bo << endl;
}

cout << "-----------------------------------------------------------------------------------------" << endl;
  

}

========================================================================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote