ЗАВДАННЯ №2.

Написати програму створення класу Stack, що реалізовує стек, який можна використовувати для збе-рігання символів. Закритими даними-членами є стек символів(char stck[SIZE]), , индекс вершини стеку а відкритими є ініціалізація стеку, розміщення символу у стек, виштовхування символу із стеку.

 

#include <iostream>

#include <stdlib.h>

#include <stdio.h>

const int SIZE = 64;

using namespace std;

class Stack

{

 

char stack[SIZE];

int index;

 

public:

void push(char a);

void pull();

void intialize();

void output();

};

void Stack::push(char a)

{

stack[index] = a;

index++;

}

void Stack::pull()

{

index--;

}

void Stack::output()

{

for(int i = 0; i < index; i++)

{

cout<<stack[i]<<" ";

}

cout<<endl;

}

void Stack::intialize()

{

for(int i = 0; i < SIZE; i++)

{

stack[i] = ' ';

}

index = 0;

}

int main()

{

Stack st;

st.intialize();

int number;

do

{

cout<<"Input number of the function:n1. Pushn2. Pulln3. Outputn4. Exitn-->";

cin>>number;

switch (number)

{

case 1:

char l;

cin>>l;

st.push(l);

break;

case 2:

st.pull();

break;

case 3:

st.output();

break;

default:

if(number != 4)

cout<<"Input errorn";

break;

}

 

}while (number != 4);

getchar();

return 0;

}

 

 

ЗАВДАННЯ №3.Написати програму створення об’єкту Cyl класу Сylinder (знаходження обчислення об'єму циліндра). Закритими даними-членами є радіус підстави , висота циліндра , а відкритими є члени-функції іні-ніціалізіції, виведення даними-членів на екран, знаходження площі об’єкта Cyl класу Сylinder.

 

 

/*

ЗАВДАННЯ №9

Написати програму створення об’єкту Cyl класу Сylinder (знаходження обчислення об'єму циліндра).

Закритими даними-членами є радіус підстави , висота циліндра , а відкритими є члени-функції іні-ніціалізіції,

виведення даними-членів на екран, знаходження площі об’єкта Cyl класу Сylinder.

*/

 

#define _USE_MATH_DEFINES

#include <iostream>

#include <stdlib.h>

#include <stdio.h>

#include <cmath>

 

using namespace std;

class Cylinder

{

int h, r, rezult;

 

public:

void setVariable(int _h, int _r);

void calc();

void output();

};

void Cylinder::setVariable(int _h, int _r)

{

h = _h;

r = _r;

}

void Cylinder::calc()

{

rezult = M_PI * pow(r, 2) * h;

}

void Cylinder::output()

{

cout<<rezult<<"m^3";

}

int main()

{

Cylinder cyl;

 

cyl.setVariable(2,4);

cyl.calc();

cout<<"rezult: ";

cyl.output();

 

getchar();

return 0;

}

 

Висновок: