fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct book { // Ορισμός εγγραφής book
  6. string title;
  7. string author;
  8. string isbn;
  9. int quantity;
  10. };
  11.  
  12. // Καταχώριση στοιχείων
  13. void readBook(book &bk) { // Παράμετρος αναφοράς (&)
  14. getline(cin, bk.title); // Η getline() διαβάζει ολόκληρη τη γραμμή
  15. getline(cin, bk.author); // π.χ. Edgar Allan Poe
  16. getline(cin, bk.isbn);
  17. cin >> bk.quantity;
  18. }
  19.  
  20. // Εμφάνιση στοιχείων
  21. void printBook(book bk) { // Παράμετρος τιμής
  22. cout<< "Book title : " << bk.title << endl;
  23. cout<< "Book author : " << bk.author << endl;
  24. cout<< "Book isbn : " << bk.isbn << endl;
  25. cout<< "Book quantity : " << bk.quantity << endl;
  26. }
  27.  
  28. int main( ){
  29.  
  30. book book1; // Ορισμός μεταβλητής μίας εγγραφής book
  31. readBook(book1); // Κλήση συνάρτησης readBook (καταχώριση)
  32. printBook(book1); // Κλήση συνάρτησης printBook (εμφάνιση)
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 15240KB
stdin
The Lord Of the Rings - The Fellowship of the Ring
J. R. R. Tolkien
116-1749849-2513827
250
stdout
Book title : The Lord Of the Rings - The Fellowship of the Ring
Book author : J. R. R. Tolkien
Book isbn : 116-1749849-2513827
Book quantity : 250