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

Программирование. Реализация методов. Задача на расстояние

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

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

«Расстояние»

Расстояние задаётся количеством километров, метров и сантиметров.

Необходимо реализовать методы:

- перевод расстояния в сантиметры;

- перевод расстояния в английские дюймы (1 дюйм = 2,5 см)

- увеличение расстояния на 1 см;

- уменьшение расстояния на 1 см;

- округление расстояния до километров (по законам математики);

- сравнение двух расстояний.

#include "stdafx.h"

#include "iostream"

class Distance {

private:

        int kilometers;

        int meters;

        int centimeters;

public:

        Distance() {} // default constructor

        Distance(int kilometers, int meters, int centimeters) { // standart constructor

                this->kilometers = kilometers;

                this->meters = meters;

                this->centimeters = centimeters;

        }

        Distance(Distance &obj) { // copy obj constructor

                kilometers = obj.kilometers;

                meters = obj.meters;

                centimeters = obj.centimeters;

        }

        //create seters

        void setKilometers(int kilometers) {

                this->kilometers = kilometers;

        }

        void setMeters(int meters) {

                this->meters = meters;

        }

        void setCentimeters(int centimeters) {

                this->centimeters = centimeters;

        }

        // create geters

        int getKilometers() {

                return kilometers;

        }

        int getMeters() {

                return meters;

        }

        int getCentimeters() {

                return centimeters;

        }

        float cantimeterToMeter() {

                return centimeters *0.001;

        }

        float dyim() {

                return centimeters / 2.5;

        }

        void addCantimeter() {

                centimeters++;

        }

        void reduseCanrimeter() {

                centimeters--;

        }

        void round() {

                if (centimeters*0.001 > 0.499) {

                        centimeters = 0;

                        kilometers++;

                }

                else {

                        centimeters = 0;

                }

                if (meters*0.01 > 0.499) {

                        meters = 0;

                        kilometers++;

                }

                else {

                        meters = 0;

                }

        }

        bool comparison(Distance &obj) {

                if (kilometers > obj.kilometers) {

                        return true;

                }

                else {

                        if (kilometers < obj.kilometers) {

                                return false;

                        }

                        else {

                                if (kilometers == obj.kilometers) {

...

Скачать:   txt (5.3 Kb)   pdf (84.7 Kb)   docx (18.1 Kb)  
Продолжить читать еще 10 страниц(ы) »
Доступно только на Essays.club