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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
class Book
{
protected:
string sTitle;
string sAuthor;
string sPublisher;
string sISBN;
int iCopyrightYear;
double dPrice;
int iCopies;
public:
//Default Constructor
Book();
//Destructor
//virtual ~Book();
//Overload Constructor
Book(string m_Title, string m_Author, string m_Publisher, string m_ISBN, int m_CopyrightYear, double m_Price, int m_Copies);
//accessor functions
string getTitle() const;
string getAuthor() const;
string getPublisher() const;
string getISBN() const;
int getCopyrightYear() const;
double getPrice() const;
int getCopies() const;
//virtual void display();
//mutator functions
void setTitle(string title);
void setAuthor(string author);
void setPublisher(string publisher);
//void setISBN(string);
//void setCopyrightYear(int);
//void setPrice(double);
//void setCopies(int);
};
Book::Book()
{
}
void Book::setTitle(string title)
{
sTitle = title;
}
void Book::setAuthor(string author)
{
sAuthor = author;
}
void Book::setPublisher(string publisher)
{
sPublisher = publisher;
}
class PrintedBook : public Book
{
protected:
int iNumPages;
public:
//default constructor
PrintedBook();
//destructor
~PrintedBook();
//overloaded constructor
PrintedBook(string sTitle, string sAuthor, string sPublisher, string sISBN, int iCopyrightYear, double dPrice, int iCopies, int iNumPages);
//accessors
void display();
int getNumPages() const;
//mutators
void setNumPages(int);
};
class AudioBook : public Book
{
protected:
int iMinutes;
string sNarrator;
public:
//default constructor
AudioBook();
//destructor
~AudioBook();
//overload constructor
AudioBook(string sTitle, string sAuthor, string sPublisher, string sISBN, int iCopyrightYear, double dPrice, int iCopies, int iMinutes, string sNarrator);
//accessors
int getMinutes() const;
string getNarrator() const;
void display() const;
//mutators
void setMinutes(int);
void setNarrator(string);
};
PrintedBook::PrintedBook()
{
}
PrintedBook::~PrintedBook()
{
}
AudioBook::AudioBook()
{
}
AudioBook::~AudioBook()
{
}
string Book::getAuthor() const
{
return sAuthor;
}
int main()
{
ifstream in_stream;
in_stream.open("C:\\Temp\\book.txt");
string type;
string title;
string author;
string publisher;
string syear;
string iyear;
string isbn;
string sprice;
string dprice;
string spages;
string ipages;
// vector that stores printed book
vector<PrintedBook> pbookset;
//vector that stores audio book
vector<AudioBook> abookset;
if (in_stream.is_open())
{
while (in_stream.good())
{
getline(in_stream, type);
//std::cout << type << std::endl;
if (type == "P")
{
PrintedBook pb1;
getline(in_stream, title);
pb1.setTitle(title);
getline(in_stream, author);
pb1.setAuthor(author);
getline(in_stream, publisher);
pb1.setPublisher(publisher);
//std::cout << "printed book" << std::endl;
//std::cout << title << std::endl;
//std::cout << author << std::endl;
//std::cout << publisher << std::endl;
// finish the rest.
pbookset.push_back(pb1);
}
if (type == "A")
{
AudioBook ab1;
getline(in_stream, title);
ab1.setTitle(title);
getline(in_stream, author);
ab1.setAuthor(author);
getline(in_stream, publisher);
ab1.setPublisher(publisher);
// finish the rest
//std::cout << "audio book" << std::endl;
//std::cout << title << std::endl;
//std::cout << author << std::endl;
//std::cout << publisher << std::endl;
abookset.push_back(ab1);
}
}
in_stream.close();
}
else
{
std::cout << "unable to open file" << std::endl << std::endl;
}
std::cout << pbookset[0].getAuthor() << std::endl;
std::cout << abookset.front().getAuthor() << std::endl;
int x;
cin >> x;
return 0;
}
|