Advertisement
Garey

Danny_20_11_2018_OOP

Nov 20th, 2018
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6. class Student {
  7.     vector <double> ocenki;
  8.     string name;
  9.     string fn;
  10.     double uspeh;
  11. public:
  12.     Student(){
  13.         this->name = "";
  14.         this->fn = "";
  15.         this->uspeh = 0.0;
  16.     }
  17.     Student (string name,string fn){
  18.         this->name = name;
  19.         this->fn = fn;
  20.     }
  21.     ~Student();
  22.  
  23.     void dobavi_ocenka(double ocenki){
  24.     this->ocenki.push_back(ocenki);
  25.     }
  26.  
  27.     void calculate();
  28.     void print_info();
  29. };
  30.  
  31. -------------------------------------------
  32.  
  33.  
  34. #include"student.h"
  35. using namespace std;
  36.  
  37. void Student :: calculate(){
  38.     double sum = 0.0;
  39.     for(unsigned i =0 ; i< ocenki.size() ; i++){
  40.         sum+=ocenki.at(i);
  41.         uspeh = sum/double (ocenki.size());
  42.     }
  43. }
  44.  
  45. void Student :: print_info(){
  46.     cout << "Name: " << name <<endl << "Nomer: " <<  fn << endl << "Ocenki: " ;
  47.     for(unsigned i = 0 ; i < ocenki.size() ; i++){
  48.         cout << ocenki[i] << " " ;
  49.     }
  50.     cout << endl << "Uspeh: " << uspeh << endl;
  51. }
  52.  
  53. Student::~Student() {};
  54.  
  55. ------------------------------
  56.  
  57. #include <iostream>
  58. #include <vector>
  59. #include <iterator>
  60. #include <algorithm>
  61.  
  62. #include <cstdlib>
  63. #include <time.h>
  64. #include "student.h"
  65.  
  66. using namespace std;
  67.  
  68. /*
  69. template<class T, class Allocator = allocator <T>>
  70. class vector {
  71. public:
  72.     explicit vector(const Allocator &a = Allocator());
  73.     explicit vector(size_t nCount, const T& value = T(), const Allocator &a = Allocator());
  74.  
  75.     vector(const vector<T, Allocator> &obj);
  76.  
  77.     template<class InIter>
  78.     vector(InIter begin, InIter end, const Allocator & a = Allocator());
  79. };
  80. */
  81.  
  82. int main() {
  83.  
  84.     /*
  85.     vector<int> v(10, 0); // vector s 10 elementa sus stoinost 0
  86.     ostream_iterator<int> out(cout, " ");
  87.  
  88.     copy(v.begin(), v.end(), out); // Kopirva vectora v ostream izhoda
  89.  
  90.     vector<int>::iterator i = v.begin(); // i sochi kum purviqt element na vectora
  91.  
  92.     *i = 125; // Zadavame mu stoinost 125
  93.  
  94.     cout << endl;
  95.  
  96.     copy(v.begin(), v.end(), out); // Kopirva vectora v ostream izhoda
  97.     v.resize(v.capacity() + 1); // Orazmerqva vectora i mu dobavq edin nov element(razmer 11)
  98.     i = v.begin(); // Vzemame purviqt element na vectora
  99.    
  100.     *i = 126; // Promenqme negovata stoinost
  101.  
  102.     cout << endl;
  103.  
  104.     copy(v.begin(), v.end(), out); // Kopirva vectora v ostream izhoda
  105.  
  106.     */
  107.  
  108.     /*srand (time(0));
  109.  
  110.     vector <int> v;
  111.     v.resize(50);
  112.     for(int i=0; i<v.capacity() ; i++){ // i < ot kapaciteta na vectora
  113.         v[i] = rand()% 64;
  114.     }
  115.     int max = v[0];
  116.  
  117.     for(int i = 0; i<v.size() ; i++){
  118.         cout<<v[i]<<" ";
  119.         if(v[i] > max) max = v[i];
  120.     }
  121.     cout<< "Max = " <<max;
  122.     */
  123.  
  124.     /*
  125.  
  126.     vector<int> v(10, 1);
  127.     vector<int>::iterator i = v.begin();
  128.  
  129.     v.insert(i, 3, 2);
  130.  
  131.     for(int i = 0; i < v.size(); i++)
  132.         cout << v[i] << "  ";
  133.  
  134.     */
  135.  
  136.     Student st1("Danny" , "17621834");
  137.     Student st2("Stef", "17621707");
  138.  
  139.     st1.dobavi_ocenka(5.30);
  140.     st1.dobavi_ocenka(6.00);
  141.     st1.calculate();
  142.     st1.print_info();
  143.  
  144.     st2.dobavi_ocenka(5.10);
  145.     st2.dobavi_ocenka(4.87);
  146.     st2.dobavi_ocenka(5.87);
  147.     st2.calculate();
  148.     st2.print_info();
  149.  
  150.     return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement