Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- using namespace std;
- struct Student {
- string first_name;
- string mid_name;
- string last_name;
- int fak_num;
- int grades[5];
- Student ()
- {
- first_name=" ";
- mid_name=" ";
- last_name=" ";
- fak_num=-1;
- for (int i=0; i<5; i++) {
- grades[i]=0;
- }
- }
- //Overwrite constructor
- Student (string first,string second, string last, int fak_number,vector <double> m)
- {
- first_name=first;
- mid_name=second;
- last_name=last;
- fak_num=fak_number;
- for (int i=0; i<5; i++) {
- if (m[i]>6 || m[i]<2)
- grades[i]=6;
- else
- grades[i]=m[i];
- }
- }
- //Copy Constructor
- Student (const Student& s) {
- cout << "Copy" << endl;
- first_name=s.first_name;
- mid_name=s.mid_name;
- last_name=s.last_name;
- fak_num=s.fak_num;
- for(int i=0; i<5; i++) {
- grades[i]=s.grades[i];
- }
- }
- void print_student(){
- string arr_subjects[5]{"Math", "Science", "Chemistry", "Art", "Music"};
- cout<<"Name: "<<first_name<<" "<<mid_name<<" "<<last_name<<"\nFaculty number: "<<fak_num<<endl;
- for(int i=0; i<5; i++) {
- cout<<"Subject: "<<arr_subjects[i]<<" Grade: "<<grades[i]<<endl;
- }
- }
- //Avarage
- double avg() {
- double sum = 0;
- double avarage = 1;
- for(int i=0; i<5; i++) {
- sum = sum + grades[i];
- }
- avarage = sum / 5;
- return avarage;
- }
- //Read
- void read(istream& in=cin){
- cout<<"Enter first name: ";
- in>>first_name;
- cout<<"Enter middle name: ";
- in>>mid_name;
- cout<<"Enter last name: ";
- in>>last_name;
- cout<<"Enter faculty number :";
- in>>fak_num;
- for(int i=0; i<5; i++) {
- in>>grades[i];
- }
- }
- };
- //Functions (Not in the Structure)
- Student read_student(){
- Student s;
- cout<<"Enter first name: ";
- cin>>s.first_name;
- cout<<"Enter middle name: ";
- cin>>s.mid_name;
- cout<<"Enter last name: ";
- cin>>s.last_name;
- cout<<"Enter faculty number :";
- cin>>s.fak_num;
- for(int i=0; i<5; i++) {
- cin>>s.grades[i];
- }
- return s;
- }
- Student& read_student_ref(){
- Student* s=new Student;
- cout<<"Enter first name: ";
- cin>>s->first_name;
- cout<<"Enter middle name: ";
- cin>>s->mid_name;
- cout<<"Enter last name: ";
- cin>>s->last_name;
- cout<<"Enter faculty number :";
- cin>>s->fak_num;
- for(int i=0; i<5; i++) {
- cin>>s->grades[i];
- }
- return *s;
- }
- int main () {
- Student s1;
- Student s2={"Boyko","Metodiev","Borisov",001,{6,6,6,6,7}};
- cout<<s2.first_name<<" "<<s2.last_name<<" "<<s2.fak_num<<" Grades: "<<s2.grades<<endl;
- Student s4=s2;
- s4.print_student();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement