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

Slides:



Advertisements
Similar presentations
EBooks and Audiobooks. This class will give you an overview of eBooks and electronic Audiobooks available from the Library. We will also explain the basic.
Advertisements

Chapter 14 Operator Overloading: What does + mean? Consider the code below. Note the multiple uses of “+”. #include using namespace std; int main() { int.
Stack and Queue Dr. Bernard Chen Ph.D. University of Central Arkansas.
. Plab – Tirgul 8 I/O streams Example: string class.
The Standard String Class Is actually a template: –typedef basic_string string This means you can have strings of things other than chars.
Overview creating your own functions calling your own functions.
Introduction to Object- Oriented Programming Prof. Shie-Jue Lee Dept. of Electrical Engineering National Sun Yat-sen University.
11 Introduction to Object Oriented Programming (Continued) Cats II.
Object-Oriented Programming in C++
Abstract Classes 1. Objectives You will be able to: Say what an abstract class is. Define and use abstract classes. 2.
Binary Search Trees II Morse Code.
1 Stacks Stack Examples Stack API More Examples/Uses Base Conversion Activation Records RPN Implementing a Stack Stacks.
String Constructors string str; // creates an empty //string string str(“abc”); // creates a string // from a C-string string str(aString); // creates.
13-1 Computing Fundamentals with C++ Object-Oriented Programming and Design, 2nd Edition Rick Mercer Franklin, Beedle & Associates, 1999 ISBN
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
1 Huffman Codes Drozdek Chapter Objectives You will be able to Construct an optimal variable bit length code for an alphabet with known probability.
1 Linked Stack Chapter 4. 2 Linked Stack We can implement a stack as a linked list. Same operations. No fixed maximum size. Stack can grow indefinitely.
Multiple Files. Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.
Copyright  Hannu Laine C++-programming Part 1 Hannu Laine.
Introduction to C++ Version 1.1. Topics C++ Structure Primitive Data Types I/O Casting Strings Control Flow.
CS 11 C++ track: lecture 5 Today: Member initialization lists Linked lists friend functions.
11 Introduction to Object Oriented Programming (Continued) Cats.
Computer Programming TCP1224 Chapter 13 Sequential File Access.
C++ Streams © Bruce M. Reynolds & Cliff Green, C++ Programming Certificate University of Washington Cliff Green.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
11-1 Computing Fundamentals with C++ Object-Oriented Programming and Design, 2nd Edition Rick Mercer Franklin, Beedle & Associates, 1999 ISBN
1 Command Processor II. 2 Command Processor Example Let's look at a simple example of a command processor using states and cities. Get initial information.
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
1 Derived Classes Chapter Objectives You will be able to: Create and use derived classes.
1 More Operator Overloading Chapter Objectives You will be able to: Define and use an overloaded operator to output objects of your own classes.
1 Linked Lists II Doubly Linked Lists Chapter 3. 2 Objectives You will be able to: Describe, implement, and use a Doubly Linked List of integers.
1 Huffman Codes Drozdek Chapter Encoding Next we will add the capability to encode a message entered as normal text. The Huffman Tree that we use.
CS 1430: Programming in C++.
1 Getting Started with C++ Part 2 Linux. 2 Getting Started on Linux Now we will look at Linux. See how to copy files between Windows and Linux Compile.
February 28, 2005 Introduction to Classes. Object Oriented Programming An object is a software bundle of related variables and methods. Software objects.
1 Modeling CDs. 2 Objectives You will be able to: Sketch a diagram showing the relationship between a class and classes that it contains a members. Define.
CSE 332: C++ template examples Today: Using Class and Function Templates Two examples –Function template for printing different types –Class template for.
1 CSC 222: Computer Programming II Spring 2004 Stacks and recursion  stack ADT  push, pop, top, empty, size  vector-based implementation, library 
11 Introduction to Object Oriented Programming (Continued) Cats.
1 Reference Variables Chapter 8 Page Reference Variables Safer version of C/C++ pointer. "Refers to" a variable. Like a pointer. Effectively.
Operator Overloading Chapter Objectives You will be able to Add overloaded operators, such as +,-, *, and / to your classes. Understand and use.
1 Derived Classes Chapter Objectives You will be able to: Create and use derived classes. Understand the meaning of polymorphism and how it works.
1 Implementing Ticket Printer. Class Diagram 2 Dependencies A class that contains objects of another class, or has a reference to another class, depends.
1 Linked Multiple Queues. 2 A real world example. Not in the book. Sometimes we have a fixed number of items that move around among a fixed set of queues.
17-1 Computing Fundamentals with C++ Object-Oriented Programming and Design, 2nd Edition Rick Mercer Franklin, Beedle & Associates, 1999 ISBN
1 Inheritance and Polymorphism Chapter Getting Started Continue the Cat Management example from previous presentation.
1 Implementing Ticket Printer. Download project from last class Downloads/2016_02_12_In_Class/
Abstract Classes 1. Objectives You will be able to: Say what an abstract class is. Define and use abstract classes. 2.
1 Huffman Codes Using Binary Files. 2 Getting Started Last class we extended a program to create a Huffman code and permit the user to encode and decode.
CSE 232: Moving Data Within a C++ Program Moving Data Within a C++ Program Input –Getting data from the command line (we’ve looked at this) –Getting data.
1 Command Processor. Objectives You will be able to Create and understand State Diagrams. Write a text based command processor with multilevel menus.
1 Using an XML Parser. 2 Objective You will be able to use a publically available open source parser to convert an XML file into an internal data structure.
The Class arrayList General purpose implementation of linear lists. Unknown number of lists.
Strings: C-strings vs. Strings as Objects
Creates the file on disk and opens it for writing
CMPE Data Structures and Algorithms in C++ September 28 Class Meeting
Dr. Bernard Chen Ph.D. University of Central Arkansas
group work #hifiTeam
The Class arrayList General purpose implementation of linear lists.
3.3 Abstract Classes, Assignment, and Casting in a Hierarchy
Strings: C-strings vs. Strings as Objects
Pointers & Functions.
Creates the file on disk and opens it for writing
Pointers & Functions.
CMSC 341 C++ and OOP.
Class rational part2.
File I/O in C++ II.
CMSC 341 C++ and OOP.
File I/O in C++ I.
Data Structures & Programming
Presentation transcript:

1 Modeling CDs (Continued)

2 Getting Started Download: _02_07_CD_Collection_Incomplete/ _02_07_CD_Collection_Incomplete/ File CD_Collection_Incomplete.zip Expand Open in Visual Studio

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 CD_Types.h _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 CD_Types.cpp _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 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 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 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 Implement Class CD _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 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 Add_Track void CD::Add_Track(const Track* track) { assert(nr_tracks < max_tracks); tracks[nr_tracks++] = track; }

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

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 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 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 A CD in iTunes

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

18 La_Luna.csv in Notepad

19 La_Luna.csv in Excel

20 CDs.csv

21 main.cpp _09_08_In_Class/Test_CD.cpp.txt _09_08_In_Class/Test_CD.cpp.txt Replace the current "Hello, World" version