Don't like ads? PRO users don't see any ads ;-)
Guest

strumienie

By: a guest on May 7th, 2012  |  syntax: None  |  size: 2.57 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //
  2. //  main.cpp
  3. //  Strumienie
  4. //
  5. //  Created by Jakub Mirota on 07.05.2012.
  6. //  Copyright (c) 2012 mirota.jakub@gmail.com. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <string>
  11. #include <iomanip>
  12. #include <fstream>
  13. #include <time.h>
  14.  
  15. using namespace std;
  16. class Konta
  17. {
  18.         string imie, nazwisko;
  19.         char plec;
  20.         int wiek;
  21.     int nr_konta;
  22.     int saldo_konta;
  23.    
  24. public:
  25.         Konta();
  26.         Konta( string im, string naz, char p , int w, int nr):imie(im), nazwisko(naz), plec(p), wiek(w), nr_konta(nr)
  27.         {  saldo_konta = 0; cout << "Konstruktor argumentowy osoby"<< endl;} ;
  28.    
  29.         friend ostream & operator<<( ostream &scr, Konta &os);
  30.         friend istream & operator>>( istream &scr, Konta &os);
  31.    
  32. };
  33.  
  34. ostream &zloty( ostream &ret);
  35.  
  36. Konta::Konta()
  37. {
  38.         cout << "Konstruktor bezargumentowy Osoby" << endl;
  39. }
  40.  
  41. ostream &zloty( ostream &ret)
  42. {
  43.     ret << " zł";
  44.     return ret;
  45.    
  46. }
  47.  
  48.  
  49. ostream & operator<<( ostream &src, Konta &os)
  50. {      
  51.    
  52.         src << setfill( '=') << setw(30) << left << "Konto" << endl;
  53.        
  54.         src << "imie: " << setw(24) << setfill(' ') << right << os.imie << endl;
  55.         src << "nazwisko: " << setw(20) << setfill(' ') << os.nazwisko << endl;
  56.         if ( os.plec == 'M')
  57.         {
  58.                 src << "plec: " << setw(24) << setfill(' ')<< "Mezczyzna" << endl;
  59.         }
  60.         else
  61.         {
  62.                 src << "plec: " << setw(24) << setfill(' ') << "Kobieta" << endl;
  63.         }
  64.    
  65.         src << "wiek: " << setw(24) << setfill(' ') << os.wiek << endl;
  66.     src << "nr konta: " << setw(20) << setfill(' ') << os.nr_konta << endl;
  67.     src << "saldo: " << setw(20) << setfill(' ') << os.saldo_konta << zloty << endl;
  68.         src.fill('=');
  69.         src.width(30);
  70.         src << "" << endl;
  71.         return src;
  72.    
  73. }
  74.  
  75. istream & operator >>( istream &scr, Konta &os)
  76. {
  77.     cout << "Podaj imie: " << endl;
  78.     scr >> os.imie;
  79.     cout << "Podaj nazwisko: " << endl;
  80.     scr >> os.nazwisko;
  81.     cout << "Podaj plec( M lub K): " << endl;
  82.     scr >> os.plec;
  83.     cout << "Podaj wiek: " << endl;
  84.     scr >> os.wiek;
  85.     cout << "Podaj numer konta: " << endl;
  86.     scr >> os.nr_konta;
  87.  
  88.     return scr;
  89. }
  90.  
  91.  
  92.  
  93.  
  94. int main()
  95. {
  96.     srand ( time(NULL) );
  97.     int a = rand()%1000+1;
  98.     int b = rand()%1000+1;
  99.     int c = rand()%1000+1;
  100.    
  101.    
  102.         Konta os("Adam", "Jackiewicz", 'M', 20, a );
  103.     Konta os2("Jan" , "Kowalski", 'M', 15,b);
  104.     Konta os3("Janina", "Nowak", 'K', 35, c );
  105.     Konta os4;
  106.    
  107.     cin >> os4;
  108.    
  109.         cout << os;
  110.     cout << os2;
  111.     cout << os3;
  112.     cout << os4;
  113.    
  114.     ofstream out("strumienie.txt");
  115.         out << os;
  116.     out << os2;
  117.     out << os3;
  118.     out << os4;
  119.         out.close();
  120.     return 0;
  121. }