Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- class Student {
- vector <double> ocenki;
- string name;
- string fn;
- double uspeh;
- public:
- Student(){
- this->name = "";
- this->fn = "";
- this->uspeh = 0.0;
- }
- Student (string name,string fn){
- this->name = name;
- this->fn = fn;
- }
- ~Student();
- void dobavi_ocenka(double ocenki){
- this->ocenki.push_back(ocenki);
- }
- void calculate();
- void print_info();
- };
- -------------------------------------------
- #include"student.h"
- using namespace std;
- void Student :: calculate(){
- double sum = 0.0;
- for(unsigned i =0 ; i< ocenki.size() ; i++){
- sum+=ocenki.at(i);
- uspeh = sum/double (ocenki.size());
- }
- }
- void Student :: print_info(){
- cout << "Name: " << name <<endl << "Nomer: " << fn << endl << "Ocenki: " ;
- for(unsigned i = 0 ; i < ocenki.size() ; i++){
- cout << ocenki[i] << " " ;
- }
- cout << endl << "Uspeh: " << uspeh << endl;
- }
- Student::~Student() {};
- ------------------------------
- #include <iostream>
- #include <vector>
- #include <iterator>
- #include <algorithm>
- #include <cstdlib>
- #include <time.h>
- #include "student.h"
- using namespace std;
- /*
- template<class T, class Allocator = allocator <T>>
- class vector {
- public:
- explicit vector(const Allocator &a = Allocator());
- explicit vector(size_t nCount, const T& value = T(), const Allocator &a = Allocator());
- vector(const vector<T, Allocator> &obj);
- template<class InIter>
- vector(InIter begin, InIter end, const Allocator & a = Allocator());
- };
- */
- int main() {
- /*
- vector<int> v(10, 0); // vector s 10 elementa sus stoinost 0
- ostream_iterator<int> out(cout, " ");
- copy(v.begin(), v.end(), out); // Kopirva vectora v ostream izhoda
- vector<int>::iterator i = v.begin(); // i sochi kum purviqt element na vectora
- *i = 125; // Zadavame mu stoinost 125
- cout << endl;
- copy(v.begin(), v.end(), out); // Kopirva vectora v ostream izhoda
- v.resize(v.capacity() + 1); // Orazmerqva vectora i mu dobavq edin nov element(razmer 11)
- i = v.begin(); // Vzemame purviqt element na vectora
- *i = 126; // Promenqme negovata stoinost
- cout << endl;
- copy(v.begin(), v.end(), out); // Kopirva vectora v ostream izhoda
- */
- /*srand (time(0));
- vector <int> v;
- v.resize(50);
- for(int i=0; i<v.capacity() ; i++){ // i < ot kapaciteta na vectora
- v[i] = rand()% 64;
- }
- int max = v[0];
- for(int i = 0; i<v.size() ; i++){
- cout<<v[i]<<" ";
- if(v[i] > max) max = v[i];
- }
- cout<< "Max = " <<max;
- */
- /*
- vector<int> v(10, 1);
- vector<int>::iterator i = v.begin();
- v.insert(i, 3, 2);
- for(int i = 0; i < v.size(); i++)
- cout << v[i] << " ";
- */
- Student st1("Danny" , "17621834");
- Student st2("Stef", "17621707");
- st1.dobavi_ocenka(5.30);
- st1.dobavi_ocenka(6.00);
- st1.calculate();
- st1.print_info();
- st2.dobavi_ocenka(5.10);
- st2.dobavi_ocenka(4.87);
- st2.dobavi_ocenka(5.87);
- st2.calculate();
- st2.print_info();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement