Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Modeling CDs (Continued). 2 Getting Started Download: 2011_02_07_CD_Collection_Incomplete/

Similar presentations


Presentation on theme: "1 Modeling CDs (Continued). 2 Getting Started Download: 2011_02_07_CD_Collection_Incomplete/"— Presentation transcript:

1 1 Modeling CDs (Continued)

2 2 Getting Started Download: http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2011_02_07_CD_Collection_Incomplete/ http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2011_02_07_CD_Collection_Incomplete/ File CD_Collection_Incomplete.zip Expand Open in Visual Studio

3 3 CD Types We have two enums for CDs: genre recording technology We will need to convert these types to strings and vice versa. Output with << operator. Let's put them into their own file: CD_Types.h Implementation of conversion function in CD_Types.cpp. Add CD_Types.h and CD_Types.cpp to the project. Note: This is not a class Use Project > Add New Item

4 4 CD_Types.h http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2011_02_07_CDs/CD_Types.h.txt #pragma once #include using namespace std; enum Recording_Technology {AAD, ADD, DDD, UNK}; ostream& operator<<(ostream& os, const Recording_Technology& rt); void Convert(const Recording_Technology& val, string& str); void Convert(const string& str, Recording_Technology& val); enum Genre {Classical, Pop, Country, Folk, Rap, Hip_Hop, Unknown}; ostream& operator<<(ostream& os, const Genre& genre); void Convert(const Genre& val, string& str); void Convert(const string& str, Genre& val);

5 5 CD_Types.cpp http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2011_02_07_CDs/CD_Types.cpp.txt #include "CD_Types.h" ostream& operator<<(ostream& os, const Recording_Technology& rt) { string str; Convert(rt, str); os << str; return os; } void Convert(const Recording_Technology& val, string& str) { switch (val) { case AAD: str = "AAD"; break; case ADD: str = "ADD"; break; case DDD: str = "DDD"; break; default: str = "UNK"; break; }

6 6 CD_Types.cpp void Convert(const string& str, Recording_Technology& val) { if (str == "AAD") val = AAD; else if (str == "ADD") val = ADD; else if (str == "DDD") val = DDD; else val = UNK; }

7 7 CD_Types.cpp ostream& operator<<(ostream& os, const Genre& genre) { string str; Convert(genre, str); os << str; return os; } void Convert(const Genre& val, string& str) { switch (val) { case Classical: str = "Classical"; break; case Pop: str = "Pop"; break; case Country: str = "Country"; break; case Folk: str = "Folk"; break; case Rap: str = "Rap"; break; case Hip_Hop: str = "Hip Hop"; break; default: str = "Unknown"; break; }

8 8 CD_Types.cpp void Convert(const string& str, Genre& val) { if (str == "Classical") val = Classical; else if (str == "Pop") val = Pop; else if (str == "Country") val = Country; else if (str == "Folk") val = Folk; else if (str == "Rap") val = Rap; else if (str == "Hip_Hop") val = Hip_Hop; else val = Unknown; } Remove defintion of enums from Track.h and CD.h Add #include "CD_Types.h" to these files.

9 9 Implement Class CD http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2010_09_08_In_Class/CD.cpp.txt #define _CRT_SECURE_NO_WARNINGS #include #include "CD_Types.h" #include "Track.h" #include "CD.h" using namespace std;

10 10 The Constructor CD::CD(string title_, string id_, string artist_, string manufacturer_, int year_, Recording_Technology technology_) : title(title_), id(id_), artist(artist_), manufacturer(manufacturer_), year(year_), technology(technology_), nr_tracks(0) {} Initialization List

11 11 Add_Track void CD::Add_Track(const Track* track) { assert(nr_tracks < max_tracks); tracks[nr_tracks++] = track; }

12 12 The Destructor CD::~CD(void) { for (int i = 0; i < nr_tracks; ++i) { delete tracks[i]; }

13 13 Total_Play_Time() int CD::Total_Play_Time() const { int total = 0; for (int i = 0; i < nr_tracks; ++i) { total += tracks[i]->Play_Time(); } return total; }

14 14 Display void CD::Display() const { cout.fill('0'); cout << "CD: " << title << endl; cout << "ID: " << id << endl; cout << "Artist: " << artist << endl; cout << "Mfgr: " << manufacturer << endl; cout << "Year: " << year << endl; cout << "Recording technology: " << technology << endl; cout << "Total play time: " << (Total_Play_Time()/ 60) << ":"; cout.width(2); cout << (Total_Play_Time()%60) << endl; cout << endl; for (int i = 0; i < nr_tracks; ++i) { cout << "\tTrack " << i+1 << ": "; tracks[i]->Display(); cout << endl; }

15 15 Capturing the Data Media players have all of the information that we need for our CD catalog. Some comes from the CD. Some comes from an on-line database. We can't get the information directly from the CD. An audio CD does not have a file system But we can copy the information from iTunes.

16 16 A CD in iTunes

17 17 CD Data The data from three CDs is available in the Downloads area of the class web site: http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2011_02_09_CD_Information/ http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2011_02_09_CD_Information/ Comma Separated Values Widely used format for structured text files. Read and written by Excel

18 18 La_Luna.csv in Notepad

19 19 La_Luna.csv in Excel

20 20 CDs.csv

21 21 main.cpp http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2010_09_08_In_Class/Test_CD.cpp.txt http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/ 2010_09_08_In_Class/Test_CD.cpp.txt Replace the current "Hello, World" version


Download ppt "1 Modeling CDs (Continued). 2 Getting Started Download: 2011_02_07_CD_Collection_Incomplete/"

Similar presentations


Ads by Google