Essays.club - Получите бесплатные рефераты, курсовые работы и научные статьи
Поиск

Классы, конструкторы, деструкторы

Автор:   •  Декабрь 6, 2022  •  Лабораторная работа  •  489 Слов (2 Страниц)  •  118 Просмотры

Страница 1 из 2

ГУАП

КАФЕДРА  43

ОТЧЕТ
ЗАЩИЩЕН С ОЦЕНКОЙ

ПРЕПОДАВАТЕЛЬ

ассистент

должность, уч. степень, звание

подпись, дата

инициалы, фамилия

ОТЧЕТ О ЛАБОРАТОРНОЙ РАБОТЕ 2

Классы, конструкторы, деструкторы

по курсу: : Структуры и алгоритмы обработки данных

РАБОТУ ВЫПОЛНИЛ

СТУДЕНТ ГР.

4134К

подпись, дата

инициалы, фамилия

Санкт-Петербург 2022

Цель работы
Изучить принципы создания классов с конструкторами, применив на практике
знания базовых синтаксических конструкций языка C++ и объектно-ориентированного программирования.

Условие

6 вариант (16 mod 10)

[pic 1]

Листинг программы

main.cpp

#include <iostream>

#include <ctime>

#include "stud.h"

using namespace std;

int main() {

    time_t seconds = time(NULL);

    tm* timeinfo = localtime(&seconds);

    int current_year = timeinfo->tm_year + 1900;

    cout<<"Current Year: "<<current_year<<endl;

    Student student1;

    Student student2("name","surname",2020);

    Student student3 = student2;

    student1.getFullName();

    student1.getCourse(current_year);

    student2.getFullName();

    student2.getCourse(current_year);

    student3.getFullName();

    student3.getCourse(current_year);

    return 0;

}

stud.h

#include <iostream>

#include <string>

using namespace std;

class Student {

    private:

        string name;

        string surname;

        int year;

    public:

        Student();

        Student(string name, string surname, int year);

        Student(Student&);

        ~Student();

        void getFullName();

        void getCourse(int current_year);

        string get_name();

        string get_surname();

        int get_year();

};

Student::Student() {

    name = "Defoult";

    surname = "Defoltov";

    year = 2015;

}

Student::Student(string n_name,string n_surname, int n_year) {

    name = n_name;

    surname = n_surname;

    year = n_year;

}

Student::Student(Student& copy) {

    name = copy.name;

    surname = copy.surname;

    year = copy.year;

}

Student::~Student() {

    cout << "Destructor worked" << endl;

    cin.get();

}

void Student::getFullName() {

    cout << "Full name of student: "<<get_surname()<<" "<<get_name()<<endl;

} 

void Student::getCourse(int current_year) {

    if (((current_year - get_year() + 1) < 1) || ((current_year - get_year() + 1)> 5)){

        cout <<"Year of admission differs from the current one by more than 5 years\nEnter a valid year of admission:" <<endl;

        cin >> year;

    }

    cout << "Student course: " << current_year - get_year() + 1 <<endl;

}

string Student::get_name() {

    return name;

}

string Student::get_surname() {

    return surname;

}

int Student::get_year() {

    return year;

}

...

Скачать:   txt (3.6 Kb)   pdf (163.5 Kb)   docx (200.7 Kb)  
Продолжить читать еще 1 страницу »
Доступно только на Essays.club