Question
I need to make my existing code simply take input from a file, not a user (as it currently is doing). I will post the
I need to make my existing code simply take input from a file, not a user (as it currently is doing). I will post the code and assignment below.
#include "stdafx.h"
#include
#include
#include
#include
#include
using namespace std;
//DVD class defined
class DVD
{
//Data member
string movieTitle, nameActorsActresses[10], actor_actress[2];
int lengthOfMovie, movieReleasedYear;
public:
//Accept the DVD information
void accept()
{
cout << " Enter the Movie Title: ";
cin >> movieTitle;
//Clears the buffer
fflush(stdin);
cout << " Enter Length of Movie: ";
cin >> lengthOfMovie;
fflush(stdin);
cout << " Enter Released Year: ";
cin >> movieReleasedYear;
fflush(stdin);
//Accepts each actor / actress name and gender
for (int i = 0; i < 2; i++)
{
cout << " Enter the Actor / Actress Name: " << i + 1 << " ";
cin >> nameActorsActresses[i];
fflush(stdin);
}
}
//Displays the DVD information
void display()
{
cout << " \t\t\t DVD";
cout << " Movie Title: " << movieTitle;
cout << " Length of Movie: " << lengthOfMovie;
cout << " Year Released: " << movieReleasedYear;
//Displays each actor / actress name and gender
for (int i = 0; i < no; i++)
{
cout << " Actors/Actresses: " << i + 1 << " " << nameActorsActresses[i];
cout << " Characters: " << i + 1 << " " << actor_actress[i];
}
}
};
//Main menu for CD or DVD selection
void menu()
{
cout << " Enter your choice: ";
cout << " 1) DVD ";
cout << " 2) Exit ";
}
//Sub main menu for Add or Remove or Update or Display selection
void subMenu()
{
cout << " 1) Add ";
cout << " 2) Remove ";
cout << " 3) Update ";
cout << " 4) Display ";
}
//Main function
int main()
{
//Creates a vector for DVD
vector
//Creates object of DVD
DVD dv;
int ch, sch, rec;
//Loops till user selects Exit
do
{
//Main menu display
menu();
//Accepts option for CD or DVD
cout << " Enter your choice: ";
cin >> ch;
fflush(stdin);
//Outer switch for CD / DVD
switch (ch)
{
//DVD
case 1:
//Sub menu displayed for add, remove, update or display
subMenu();
fflush(stdin);
//Accept choice for add, remove, update or display
cout << " Enter your choice: ";
cin >> sch;
fflush(stdin);
//Inner switch for DVD - add, remove, update or display
switch (sch)
{
//Add
case 1:
//Accept DVD information
dv.accept();
//Adds record to vector DVD
myDVD.push_back(dv);
break;
//Delete
case 2:
//Accepts record number for delete
cout << " Enter the record to delete: ";
cin >> rec;
//Removes record from the vector DVD
myDVD.erase(myDVD.begin() + (rec - 1));
break;
//Update
case 3:
//Accepts the record number for update
cout << " Enter the record number to update: ";
cin >> rec;
//Accept data for update
dv.accept();
//Inserts the update record
myDVD.insert(myDVD.begin() + (rec - 1), dv);
//Removes the old record
myDVD.erase(myDVD.begin() + rec);
break;
//Display
case 4:
//Creates Iterator class object
vector
//Iterates till end of the vector DVD
for (it = myDVD.begin(); it < myDVD.end(); it++)
it->display();
break;
}
break;
case 2:
exit(0);
//Invalid choice
default:
cout << " Invalid choice!";
}
} while (1);
}
You are to design a system to keep track of either a CD or DVD/Blu-ray collection. The program will only work exclusively with either CDs or DVDs/Blu-rays since some of the data is different. Which item your program will work with will be up to you. The data will be stored in a file. The data from the file will be stored in a text (.TXT) file as records. Each CD/DVD/Blu-ray in the collection will be represented as a class, so there will be a class that is the CD/DVD/Blu-ray. The CD class will be limited to five (5) songs, and the class will need to keep an array of five (5) strings for the song titles. It should also maintain the length of each song and the total length of the CD, as well as the artist name. The DVD/Blu-ray class will have a data member for the title of the movie, length of the movie, the year of the movie, and for the names of two of the main actors in the movie. There will be a class that maintains the list of CD/DVDs/Blu-rays. This list can be limited to just 5 CD/DVD/Blu-rays and provide a method to add a CD/DVD/Blu-ray, to remove a CD/DVD/Blu-ray, and to update a CD/DVD/Blu-ray.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started