lwytop

Wonyoung Lee mp8 part1

Jul 23rd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. //Wonyoung Lee mp8 part1.
  2. //Book.h file.
  3.  
  4. #pragma once
  5. #include <iostream>
  6.  
  7. class Book
  8. {
  9. private:
  10.     std::string authorName;
  11.     std::string title;
  12.     int isbn;
  13. public:
  14.     void Constructor();
  15.     void GetData(std::string, std::string, int);
  16.     void print(int);
  17.     int GetISBN(int);
  18. };
  19.  
  20.  
  21. //Book.cpp file
  22.  
  23. #include "stdafx.h"
  24. #include "Book.h"
  25. #include <iostream>
  26. #include <string>
  27.  
  28. void Book::Constructor() {
  29.     Book::authorName = "No name";
  30.     Book::title = "Unknown title";
  31.     Book::isbn = 0;
  32. }
  33.  
  34. void Book::GetData(std::string authorName, std::string title, int isbn)
  35. {
  36.     Book::authorName = authorName;
  37.     Book::title = title;
  38.     Book::isbn = isbn;
  39. }
  40.  
  41. void Book::print(int count)
  42. {
  43.    
  44.     std::cout << "The information for book " << count << " is: " << std::endl;
  45.     std::cout << authorName << " / " << title << " / "<< isbn << std::endl;
  46. }
  47.  
  48. int Book::GetISBN()
  49. {
  50.     return isbn;
  51. }
  52.  
  53. // Main.cpp file
  54.  
  55.  
  56. // Wonyoung Lee Machine Problem 8 part1.
  57.  
  58. #include "stdafx.h"
  59. #include <iostream>
  60. #include <string>
  61. #include <fstream>
  62. #include "Book.h"
  63.  
  64. using namespace std;
  65.  
  66. int main()
  67. {
  68.  
  69.     string data;
  70.     int count = 1;
  71.     ifstream inputFile;
  72.     inputFile.open("c:\\temp\\mp7.txt");
  73.    
  74.  
  75.     while (!inputFile.eof()) {
  76.  
  77.  
  78.         if (count == 1) {
  79.             Book book1;
  80.  
  81.             book1.Constructor();
  82.  
  83.             book1.print(count);
  84.         }
  85.    
  86.         else if (count > 1) {
  87.            
  88.             getline(inputFile, data);
  89.             string authorName = data;
  90.             getline(inputFile, data);
  91.             string title = data;
  92.             int isbn;
  93.             inputFile >> isbn;
  94.  
  95.             Book book2;
  96.  
  97.             book2.GetData(authorName, title, isbn);
  98.  
  99.             book2.print(count);
  100.  
  101.             cout << "Book" << count << " has ISBN " << book2.GetISBN() << endl;
  102.  
  103.            
  104.         }
  105.  
  106.         count++;
  107.     }
  108.  
  109.  
  110.     return 0;
  111. }
Add Comment
Please, Sign In to add comment