peterzig

[PO] Klasy - Numer Telefonu

Apr 4th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. // [PO] Klasy Numer Telefonu.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <conio.h>
  6. #include <iostream>
  7. #include <stdio.h>
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. class NumerTelefonu
  13. {
  14.     string rodzaj;
  15.     int kierunkowy;
  16.     int numer;
  17. public:
  18.     NumerTelefonu(string, int, int);
  19.     string f_rodzaj();
  20.     int kierun();
  21.     int Numer();
  22. };
  23.  
  24. NumerTelefonu::NumerTelefonu(string _rodzaj, int _kierunkowy, int _numer)
  25. {
  26.     rodzaj = _rodzaj;
  27.     kierunkowy = _kierunkowy;
  28.     numer = _numer;
  29. }
  30.  
  31. string NumerTelefonu::f_rodzaj()
  32. {
  33.     return rodzaj;
  34. }
  35.  
  36. int NumerTelefonu::kierun()
  37. {
  38.     return kierunkowy;
  39. }
  40.  
  41. int NumerTelefonu::Numer()
  42. {
  43.     return numer;
  44. }
  45.  
  46. class Kontakt
  47. {
  48.     char imie[80];
  49.     int wiek;
  50.  
  51. public:
  52.     void zapamietaj(char * napis, int wiek);
  53.     void wypisz();
  54. };
  55.  
  56. void Kontakt::zapamietaj(char* napis, int _wiek)
  57. {
  58.     strcpy(imie, napis);
  59.     wiek = _wiek;
  60. }
  61.  
  62. void Kontakt::wypisz()
  63. {
  64. cout << "\t" << imie << ", lat: " << wiek << endl;
  65. }
  66.  
  67.  
  68. int main()
  69. {
  70.     Kontakt student1, student2;
  71.  
  72.     int numer, kierunkowy;
  73.     string typ;
  74.     cout << "Podaj numer telefonu \n";
  75.     cin >> numer;
  76.     cout << "Podaj kierunkowy \n";
  77.     cin >> kierunkowy;
  78.     cout << "Podaj typ \n";
  79.     cin >> typ;
  80.     NumerTelefonu nowy(typ, kierunkowy, numer);
  81.  
  82.     cout << "Wpisane Dane: \n";
  83.     cout << nowy.f_rodzaj() <<"  +" << nowy.kierun() << nowy.Numer() <<endl;
  84.  
  85.  
  86.     // ponizej inna para kaloszy ;)
  87.     string imie1;
  88.     string nazwisko1;
  89.     string imie2;
  90.     string nazwisko2;
  91.     int wiek1;
  92.     int wiek2;
  93.     cout << "STUDENT1" << endl;
  94.     cout << "Podaj swoje imie [ENTER] nazwisko:" << endl;
  95.     cin >> imie1 >> nazwisko1;
  96.     cout << "Podaj swoj wiek" << endl;
  97.     cin >> wiek1;
  98.     cout << "STUDENT2" << endl;
  99.     cout << "Podaj swoje imie i nazwisko:" << endl;
  100.     cin >> imie2 >> nazwisko2;
  101.     cout << "Podaj swoj wiek" << endl;
  102.     cin >> wiek2;
  103.     cout << "Wprowadzone Dane" << endl;
  104.     cout << "Student nr 1: " << imie1 << " " << nazwisko1 << " lat: " << wiek1 << endl;
  105.     cout << "Student nr 2: " << imie2 << " " << nazwisko2 << " lat: " << wiek2 << endl;
  106.     cout << "Program zakonczy swoje dzialanie" << endl;
  107.     cout << "Mozna bezpiecznie wylaczyc komputer :)" << endl;
  108.  
  109.     _getch();
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment