Міністрество освіти і науки, молоді та спорту України
Національний університет «Львівська політехніка»
Кафедра ЕОМ
Звіт
про виконання лабораторної роботи №4
Львів 2015
//main.cpp
#include <iostream>
#include "GasStation.h"
using namespace std;
int main(){
CGasStation lukoil(10000, 5674, 15000, 6783, 9000, 4536, 11000, 8976, 15);
while (true){
cout << "\n===================\nget - 1\nadd - 2\nref - 3\nchange - 4\n===================\n";
int a;
cin >> a;
if ((a!=1)&&(a!=2)&&(a!=3)&&(a!=4)) break;
switch (a){
case 1: lukoil.fnGet();
break;
case 2: lukoil.fnAddPatrol();
break;
case 3:lukoil.fnRefuel();
break;
case 4: lukoil.fnChangeTheVolume();
default: break;
}
}
}
//gasstation.h
#pragma once
class CGasStation
{
public:
CGasStation(int iVolume1, int iVolumeOfStocks1, int iVolume2, int iVolumeOfStocks2,
int iVolume3, int iVolumeOfStocks3, int iVolume4, int iVolumeOfStocks4, int iCapacity);
~CGasStation();
void fnGet();
void fnAddPatrol();
void fnRefuel();
void fnChangeTheVolume();
private:
int m_iVolume1, m_iVolume2, m_iVolume3, m_iVolume4,
m_iVolumeOfStocks1, m_iVolumeOfStocks2, m_iVolumeOfStocks3, m_iVolumeOfStocks4,
m_iCapacity;
};
//gasstation.cpp
#include "GasStation.h"
#include "iostream"
using namespace std;
CGasStation::CGasStation(int iVolume1, int iVolumeOfStocks1, int iVolume2, int iVolumeOfStocks2,
int iVolume3, int iVolumeOfStocks3, int iVolume4, int iVolumeOfStocks4, int iCapacity){
m_iVolume1 = iVolume1;
m_iVolume2 = iVolume2;
m_iVolume3 = iVolume3;
m_iVolume4 = iVolume4;
m_iVolumeOfStocks1 = iVolumeOfStocks1;
m_iVolumeOfStocks2 = iVolumeOfStocks2;
m_iVolumeOfStocks3 = iVolumeOfStocks3;
m_iVolumeOfStocks4 = iVolumeOfStocks4;
m_iCapacity = iCapacity;
}
CGasStation::~CGasStation(){
}
void CGasStation::fnGet(){
cout << "Type 1: " << "Volume = " << m_iVolume1 << "; VolumeOfStocks = " << m_iVolumeOfStocks1 << ";\n";
cout << "Type 2: " << "Volume = " << m_iVolume2 << "; VolumeOfStocks = " << m_iVolumeOfStocks2 << ";\n";
cout << "Type 3: " << "Volume = " << m_iVolume3 << "; VolumeOfStocks = " << m_iVolumeOfStocks3 << ";\n";
cout << "Type 4: " << "Volume = " << m_iVolume4 << "; VolumeOfStocks = " << m_iVolumeOfStocks4 << ";\n";
cout << "Capacity = "<< m_iCapacity << ";\n";
}
void CGasStation::fnAddPatrol(){
int iType; int iVolume;
cout << "Vvedu tup skhovushcha(1,2,3 abo 4): ";
cin >> iType;
cout << "\nVVedu ob'em paluva: ";
cin >> iVolume;
switch (iType){
case 1: m_iVolumeOfStocks1 += iVolume;
if (m_iVolumeOfStocks1 > m_iVolume1){
m_iVolumeOfStocks1 = m_iVolume1;
}
break;
case 2: m_iVolumeOfStocks2 += iVolume;
if (m_iVolumeOfStocks2 > m_iVolume2){
m_iVolumeOfStocks2 = m_iVolume2;
}
break;
case 3: m_iVolumeOfStocks3 += iVolume;
if (m_iVolumeOfStocks3 > m_iVolume3){
m_iVolumeOfStocks3 = m_iVolume3;
}
break;
case 4: m_iVolumeOfStocks4 += iVolume;
if (m_iVolumeOfStocks4 > m_iVolume4){
m_iVolumeOfStocks4 = m_iVolume4;
}
break;
default: break;
}
}
void CGasStation::fnRefuel(){
int iType; int iVolume;
cout << "Vvedu tup paluva(1,2,3 abo 4): ";
cin >> iType;
cout << "\nVVedu ob'em paluva: ";
cin >> iVolume;
switch (iType){
case 1:
if (m_iVolumeOfStocks1 < iVolume){
cout << "Nedostatnio paluva\n\n";
break;
}
m_iVolumeOfStocks1 -= iVolume;
cout << "time: "<<(int)(iVolume / m_iCapacity) << "khv\n";
break;
case 2:
if (m_iVolumeOfStocks2 < iVolume){
cout << "Nedostatnio paluva\n\n";
break;
}
m_iVolumeOfStocks2 -= iVolume;
cout << "time: " << (int)(iVolume / m_iCapacity) << "khv\n";
break;
case 3:
if (m_iVolumeOfStocks3 < iVolume){
cout << "Nedostatnio paluva\n\n";
break;
}
m_iVolumeOfStocks3 -= iVolume;
cout << "time: " << (int)(iVolume / m_iCapacity) << "khv\n";
break;
case 4:
if (m_iVolumeOfStocks4 < iVolume){
cout << "Nedostatnio paluva\n\n";
break;
}
m_iVolumeOfStocks4 -= iVolume;
cout << "time: " << (int)(iVolume / m_iCapacity) << "khv\n";
break;
default: break;
}
}
void CGasStation::fnChangeTheVolume(){
int iType; int iVolume;
cout << "Vvedu tup skhovushcha(1,2,3 abo 4): ";
cin >> iType;
cout << "\nVVedu ob'em: ";
cin >> iVolume;
switch (iType){
case 1: m_iVolume1 = iVolume;
if (m_iVolumeOfStocks1 > iVolume){
m_iVolumeOfStocks1 = iVolume;
}
break;
case 2: m_iVolume2 = iVolume;
if (m_iVolumeOfStocks2 > iVolume){
m_iVolumeOfStocks2 = iVolume;
}
break;
case 3: m_iVolume3 = iVolume;
if (m_iVolumeOfStocks3 > iVolume){
m_iVolumeOfStocks3 = iVolume;
}
break;
case 4: m_iVolume4 = iVolume;
if (m_iVolumeOfStocks4 > iVolume){
m_iVolumeOfStocks4 = iVolume;
}
break;
default: break;
}
}