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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
// media4.h
#ifndef _MEDIA4
#define _MEDIA4
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstring>
using namespace std;
//******************************************** RateType *****
enum MediaRatingType {NR, G, PG, PG13, R, X};
string RatingToStr( MediaRatingType rating);
// Converts the MediaRatingType to string
// pre: rating has a value
// post: returns a string based on the rating
MediaRatingType StrToRating( string rating);
// Converts the str to MediaRatingType
// pre: rating has a value
// post: returns rating based on the string
//******************************************** MediaType *****
enum MediaType {ERR_TYPE, VHS, DVD, GAME};
MediaType FindType(int seqNum);
// Determines the type of item from the sequence number
// Pre: seqNum must have a positive value from 1 - 1000
// Post: the type is determined from the seqNum and returned to caller
string MediaToStr( MediaType t);
// Converts the MediaType to string
// pre: t has a value
// post: returns a string based on t
//******************************************** MediaKindType *****
enum MediaKindType {ERR_KIND, ACTION, DRAMA, HORROR,
SCIFI, COMEDY,
SUSPENSE, FAMILY};
MediaKindType FindKind(int seqNum);
// Determines the kind of item from the sequence number
// Pre: seqNum must have a positive value from 1 - 1000
// Post: the kind is determined from the seqNum and returned to caller
string KindToStr( MediaKindType kind);
// Converts the MediaKindType to string
// pre: kind has a value
// post: returns a string based on the kind
//******************************************** MediaClass *****
class MediaClass
{
public:
MediaClass( );
// default constructor
// Sets the initial values of the member data
bool SetMedia(string title, int seq, string rating, int qty);
// Sets the member data if valid
// Pre: parameters must have values
// Post: valid parameters - member data is set to parameter values
// return true
// invalid - member data unchanged
// return false
bool SetKey (string title, string type);
// Sets the title and seq num (based on type) for the media item
// Pre: parameters must have a value
// Post: valid parameters - title & seq num is set to parameter values
// return true
// invalid - member data unchanged
// return false
void InputMedia( );
// Gets the valid data member values for a
// MediaClass from standard input
// pre: none
// post: data members of MediaClass have valid values
void ReadMedia(istream &input);
// Gets the member data from an input stream
// record format: title#seqnum#rating#qty
// Pre: input stream must be open
// Post: media member data has been extracted from the stream
void DisplayMedia(ostream& output) const;
// Prints the member data to an output stream
// record format: title type kind rating qty
// Pre: output stream must be open
// member data must have value
// Post: media member data has been inserted into the stream
void WriteMedia(ostream &output) const;
// Outputs the member data to an output stream
// record format: title#seqnum#rating#qty
// Pre: output stream must be open
// member data must have values
// Post: media member data has been inserted into the stream
string ReturnTitle( ) const;
// Returns the item title
// Pre: member data must have value
// Post: returns title of item to the caller
MediaType ReturnType( ) const;
// Returns the item type based on the sequence number
// Example: VHS, DVD, GAME
// Pre: member data must have value
// Post: returns type of item to the caller
MediaKindType ReturnKind( ) const;
// Returns the item kind based on the sequence number
// Example: ACTION, DRAMA, HORROR, SCIFI, COMEDY, SUSPENSE, FAMILY
// Pre: member data must have value
// Post: returns kind of item to the caller
MediaRatingType ReturnRating( ) const;
// Returns the item rate
// Example: G, PG, PG13, R, X
// Pre: member data must have value
// Post: returns rating of item to the caller
int ReturnQty( ) const;
// Returns theqty of the item
// Pre: member data must have value
// Post: returns qty of item to the caller
void UpdateQty(int addQty);
// Updates the qty of the item by adding the additional qty
// if addQty is negative then qty is reduced
// Pre: member data must have value
// Post: qty of the item has been updated by the addqty
bool EqualTitle(MediaClass media) const;
// Compares two media classes based on the title
// Pre: member data must have a value
// Post: Returns true if the titles are the same, false otherwise
// Not case sensitive (ie Shrek == SHREK == shrek)
// relational operators use key: title & type
bool operator==(const MediaClass & media) const;
// Compares this MediaClass object with media for equality
// Pre: Both class objects have value
// Post:
// function value = true if the objects are equal
// false otherwise
bool operator!=(const MediaClass & media) const;
// Compares this MediaClass object with media for inequality
// Pre: Both class objects have value
// Post:
// function value = true if the objects are not equal
// false otherwise
bool operator<=(const MediaClass & media) const;
// Compares this MediaClass object <= media
// Pre: Both class objects have value
// Post:
// function value = true if this object <= media
// false otherwise
bool operator>=(const MediaClass & media) const;
// Compares this MediaClass object >= media
// Pre: Both class objects have value
// Post:
// function value = true if this object >= media
// false otherwise
bool operator<(const MediaClass & media) const;
// Compares this MediaClass object < media
// Pre: Both class objects have value
// Post:
// function value = true if this object < media
// false otherwise
bool operator>(const MediaClass & media) const;
// Compares this MediaClass object > media
// Pre: Both class objects have value
// Post:
// function value = true if this object > media
// false otherwise
friend istream& operator>>(istream& in, MediaClass& m);
// friend function for input
// Pre: istream must have a value
// Post: Data members in MediaClass m will have a value
// istream is returned.
friend ostream& operator<<(ostream& out, const MediaClass& m);
// friend function for output
// Pre: Data members in MediaClass m have a value
// ostream must have value
// Post: All data members in MediaClass m have been inserted into
// ostream. ostream is returned.
private:
string title; // title of the media item
int seqNum; // seq number of the media item
MediaRatingType rating; // media rating
int qty; // qty of media item
};
#endif
|