Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Wonyoung Lee mp8 part1.
- //Book.h file.
- #pragma once
- #include <iostream>
- class Book
- {
- private:
- std::string authorName;
- std::string title;
- int isbn;
- public:
- void Constructor();
- void GetData(std::string, std::string, int);
- void print(int);
- int GetISBN(int);
- };
- //Book.cpp file
- #include "stdafx.h"
- #include "Book.h"
- #include <iostream>
- #include <string>
- void Book::Constructor() {
- Book::authorName = "No name";
- Book::title = "Unknown title";
- Book::isbn = 0;
- }
- void Book::GetData(std::string authorName, std::string title, int isbn)
- {
- Book::authorName = authorName;
- Book::title = title;
- Book::isbn = isbn;
- }
- void Book::print(int count)
- {
- std::cout << "The information for book " << count << " is: " << std::endl;
- std::cout << authorName << " / " << title << " / "<< isbn << std::endl;
- }
- int Book::GetISBN()
- {
- return isbn;
- }
- // Main.cpp file
- // Wonyoung Lee Machine Problem 8 part1.
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- #include "Book.h"
- using namespace std;
- int main()
- {
- string data;
- int count = 1;
- ifstream inputFile;
- inputFile.open("c:\\temp\\mp7.txt");
- while (!inputFile.eof()) {
- if (count == 1) {
- Book book1;
- book1.Constructor();
- book1.print(count);
- }
- else if (count > 1) {
- getline(inputFile, data);
- string authorName = data;
- getline(inputFile, data);
- string title = data;
- int isbn;
- inputFile >> isbn;
- Book book2;
- book2.GetData(authorName, title, isbn);
- book2.print(count);
- cout << "Book" << count << " has ISBN " << book2.GetISBN() << endl;
- }
- count++;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment