Скриншот вывода программы

Лабораторная работа №4

«Инкапсуляция. Реализация простых классов в языке С++.»

 

 

Выполнила: студентка группы ИСТбд-11 Петрова А.А

Проверила: Москвичева М.Г

 

Ульяновск, 2020 г.

 

Лабораторная работа №4

«Инкапсуляция. Реализация простых классов в языке С++.»

Задание: Выберите на ваше усмотрение классификацию некоторых объектов реального мира. Каждый объект должен иметь от трех до пяти параметров, ха-рактеризующих его. Общее количество объектов должно быть не менее семи, причем они должны иметь общие характеристики и возможности реализации своих действий или действий над ними (см. пример). Реализуйте описание каж-дого из классов нижнего уровня средствами языка С++.

Для выполнения лабораторной работы достаточно реализовать классы «собака» и «кошка».

Скриншот кода программы

Main.cpp

#include "stdafx.h"

#include <iostream>

#include "Prose.h"

#include "Poetry.h"

 

int main()

{

   setlocale(LC_ALL, "rus");

 

   Prose book1;

   book1.Print_basic_info();

   book1.Set_name("Избранное");

   book1.Set_author("Лермонтов М.Ю.");

   book1.Set_year(1984);

   book1.Set_rating(8.5);

   book1.Set_genre("Сборник");

   book1.Print_basic_info();

 

   Prose book2("Собачье сердце", "Булгаков М.Ю.", 2013, 9.1, "Повесть");

   book2.Print_basic_info();

 

   Poetry book3;

   book3.Print_basic_info();

   book3.Set_name("ХХ век: Поэт и Время. Стихотворения.");

   book3.Set_author("Рожденственский Р.И.");

   book3.Set_year(1988);

   book3.Set_rating(8.9);

   book3.Set_genre("Сборник стихотворений");

   book3.Print_basic_info();

 

   Poetry book4("Гамлет", "Шекспир В.", 1956, 8.8, "Пьеса");

   book4.Print_basic_info();

 

return 0;

}

Prose.h

#pragma once

class Prose

{

private:

const char* name;

const char* author;

int year;

double rating;

const char* sphere;

const char* genre;

const char* struct_prose;

public:

Prose();

Prose(const char*, const char*, int, double, const char*);

 

   const char* Get_name();

   void Set_name(const char*);

 

   const char* Get_author();

   void Set_author(const char*);

 

   int Get_year();

   void Set_year(int);

 

   double Get_rating();

   void Set_rating(double);

 

   const char* Get_sphere();

 

   const char* Get_genre();

   void Set_genre(const char*);

 

   const char* Get_struct_prose();

 

   void Print_basic_info();

 

   ~Prose();

};

Prose.cpp

#include "stdafx.h"

#include "Prose.h"

#include <iostream>

 

Prose::Prose()

{

   name = "";

   author = "";

   year = 0;

   rating = 0;

   sphere = "Художественная литература";

   genre = "";

   struct_prose = "Проза";

}

 

Prose::Prose(const char* name, const char* author, int year, double rating, const char* genre)

{

   this->name = name;

   this->author = author;

   this->year = year;

   this->rating = rating;

   this->genre = genre;

   sphere = "Художественная литература";

   struct_prose = "Проза";

}

 

const char* Prose::Get_name() { return name; }

void Prose::Set_name(const char* name) { this->name = name; }

 

const char* Prose::Get_author() { return author; }

void Prose::Set_author(const char* author) { this->author = author; }

 

int Prose::Get_year() { return year; }

void Prose::Set_year(int year) { this->year = year; }

 

double Prose::Get_rating() { return rating; }

void Prose::Set_rating(double rating) { this->rating = rating; }

 

const char* Prose::Get_sphere() { return sphere; }

 

const char* Prose::Get_genre() { return genre; }

void Prose::Set_genre(const char* genre) { this->genre = genre; }

 

const char* Prose::Get_struct_prose() { return struct_prose; }

 

void Prose::Print_basic_info()

{

   std::cout << "Название книги: <<" << Get_name() << ">>" << std::endl;

   std::cout << "Автор книги: " << Get_author() << std::endl;

   std::cout << "Год издания: " << Get_year() << std::endl;

   std::cout << "Рейтинг книги: " << Get_rating() << std::endl;

   std::cout << "Жанр книги: " << Get_genre() << std::endl;

   std::cout << "Литературная сфера: " << Get_sphere() << std::endl;

   std::cout << "Структура изложения: " << Get_struct_prose() << std::endl;

   std::cout << std::endl;

}

 

Prose::~Prose()

{

}

Poetry.h

#pragma once

class Poetry

{

private:

   const char* name;

   const char* author;

   int year;

   double rating;

   const char* sphere;

   const char* genre;

   const char* struct_poem;

public:

   Poetry();

   Poetry(const char*, const char*, int, double, const char*);

 

   const char* Get_name();

   void Set_name(const char*);

 

   const char* Get_author();

   void Set_author(const char*);

 

   int Get_year();

   void Set_year(int);

 

   double Get_rating();

   void Set_rating(double);

 

   const char* Get_sphere();

 

   const char* Get_genre();

   void Set_genre(const char*);

 

   const char* Get_struct_poem();

 

   void Print_basic_info();

 

   ~Poetry();

};

Poetry.cpp

#include "stdafx.h"

#include "Poetry.h"

#include <iostream>

 

 

Poetry::Poetry()

{

   name = "";

   author = "";

   year = 0;

   rating = 0;

   sphere = "Художественная литература";

   genre = "";

   struct_poem = "Поэзия";

}

 

Poetry::Poetry(const char* name, const char* author, int year, double rating, const char* genre)

{

   this->name = name;

   this->author = author;

   this->year = year;

   this->rating = rating;

   this->genre = genre;

   sphere = "Художественная литература";

   struct_poem = "Поэзия";

}

 

const char* Poetry::Get_name() { return name; }

void Poetry::Set_name(const char* name) { this->name = name; }

 

const char* Poetry::Get_author() { return author; }

void Poetry::Set_author(const char* author) { this->author = author; }

 

int Poetry::Get_year() { return year; }

void Poetry::Set_year(int year) { this->year = year; }

 

double Poetry::Get_rating() { return rating; }

void Poetry::Set_rating(double rating) { this->rating = rating; }

 

const char* Poetry::Get_sphere() { return sphere; }

 

const char* Poetry::Get_genre() { return genre; }

void Poetry::Set_genre(const char* genre) { this->genre = genre; }

 

const char* Poetry::Get_struct_poem() { return struct_poem; }

 

void Poetry::Print_basic_info()

{

   std::cout << "Название книги: <<" << Get_name() << ">>" << std::endl;

   std::cout << "Автор книги: " << Get_author() << std::endl;

   std::cout << "Год издания: " << Get_year() << std::endl;

   std::cout << "Рейтинг книги: " << Get_rating() << std::endl;

   std::cout << "Жанр книги: " << Get_genre() << std::endl;

   std::cout << "Литературная сфера: " << Get_sphere() << std::endl;

   std::cout << "Структура изложения: " << Get_struct_poem() << std::endl;

   std::cout << std::endl;

}

 

Poetry::~Poetry()

{

}

Скриншот вывода программы


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: