1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// Rich Dunne
// Final: This program will allow the user to keep track of a DVD collection. The program provides a menu for the user to be able to add, delete, update and display the information in a DVD.
#include "DVD.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
// Function prototypes
void menu(vector<DVD>&);
void addDVD(int, vector<DVD>&);
void removeDVD();
void displayCollection(int, vector<DVD>& dvd);
int main()
{
// Create vector of DVD objects called dvdVector
// Add object to vector at end of addDVD
vector<DVD> dvdVector(5);
// Call menu function
menu(dvdVector);
//TODO: DVD List Class has methods to add DVD, remove DVD, update DVD
}
void menu(vector<DVD>& dvdVector)
{
static int numDVD; // Number of DVDs user wants to add
string strNum,
strChoice; // Menu choice
int choice;
// Dynamically allocate array of DVD objects
// TODO: DON'T FORGET TO DELETE AT END OF PROGRAM
//DVD *dvd = new DVD{DVD(title, year, length, actorOne, actorTwo)};
// Create vector of DVD objects called dvdVector
// Add object to vector at end of addDVD
//vector<DVD> dvdVector(5);
cout << "DVD Collection Main Menu" << endl
<< "--------------------------" << endl
<< "1. Add DVDs" << endl
<< "2. Edit DVDs" << endl
<< "3. Remove DVDs" << endl
<< "4. Display Collection" << endl
<< "5. Exit" << endl
<< "Choose an option (1-5): ";
getline(cin, strChoice);
choice = atoi(strChoice.c_str()); // Convert string to int
switch (choice)
{
case 1:
cout << endl << "How many DVDs would you like to add? (no more than 5): ";
getline(cin, strNum);
numDVD = atoi(strNum.c_str());
while(numDVD > 5)
{
cout << endl << "How many DVDs would you like to add? (no more than 5): ";
getline(cin, strNum);
numDVD = atoi(strNum.c_str());
}
addDVD(numDVD, dvdVector); // Call addDVD function
break;
case 2:
// TODO: Get collection, ask which DVD user would like to edit, call addDVD function
case 3:
// TODO: Get collection, ask which DVD user would like to delete, call removeDVD function
case 4:
// TODO: If no DVDs, error else
//displayCollection(numDVD, dvd);
cout << "DVD: " << dvdVector[0].getTitle() << endl;
break;
case 5:
cout << endl << "Terminating program." << endl << endl;
exit;
break;
default:
exit;
}
cout << "DVD: " << dvdVector[0].getTitle() << endl;
}
void addDVD(int numDVD, vector<DVD>& dvdVector)
{
string title, // DVD title
actorOne, // Name of actor one
actorTwo, // Name of actor two
strLength, // Length of DVD (in string for getline)
strYear; // Year of DVD (in string for getline)
int length, // Length of DVD
year, // Year of DVD
i; // Loop counter
// TODO: Make it so file is appended instead of overwritten
ofstream outputFile("dvds.txt"); // Create dvds.txt
for(i = 0; i < numDVD; i++)
{
cout << "DVD #" << i+1 << endl
<< "----------------" << endl;
cout << "DVD title: ";
getline(cin, title);
outputFile << title << endl;
cout << "Year: ";
getline(cin, strYear);
year = atoi(strYear.c_str());
outputFile << year << endl;
cout << "Length (in minutes): ";
getline(cin, strLength);
length = atoi(strLength.c_str());
outputFile << length << endl;
cout << "Main Actor: ";
getline(cin, actorOne);
outputFile << actorOne << endl;
cout << "Supporting Actor: ";
getline(cin, actorTwo);
outputFile << actorTwo << endl;
cout << endl;
// Create instance of DVD class named same as current i
DVD i(title, year, length, actorOne, actorTwo);
i.setTitle(title);
i.setYear(year);
i.setLength(length);
i.setActorOne(actorOne);
i.setActorTwo(actorTwo);
dvdVector.push_back(i);
}
// Close file
outputFile.close();
// Return to menu
//menu();
}
|