
- •Практичне заняття 8 Теоретична частина
- •Завдання
- •Int main()
- •Void push(int var)
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Лабораторне заняття 9 Теоретична частина
- •Зміст завдання
- •Лабораторне заняття 10 Теоретична частина
- •Практичне заняття 9 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Практичне заняття 10-11 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Лабораторне заняття 11-12 Теоретична частина
- •Завдання 1
- •Завдання 2
- •Завдання 3
- •Int main()
- •Практичне заняття 12-13 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Лабораторне заняття 13 Теоретична частина
- •Завдання 1
- •Int main()
- •Завдання 2
- •Практичне заняття 14 Теоретична частина
- •Завдання
- •Int main()
- •Int main()
- •Лабораторне заняття 14 Теоретична частина
- •Завдання
Int main()
{clrscr();
person* persPtr[100];
char choice;
int n=0;
do{
cout<<"Студент(s) чи професор(p):»;
cin>>choice;
if(choice==’s’)
persPtr[n]=new student;
else
persPtr[n]=new professor;
persPtr[n++]->getdata();
cout<<”Continue y/n”;
cin>>choice;
} while (choice==’y’);
for(int j=0;j<n;j++)
{persPtr[j]->putname();
if(persPtr[j]->isoutstanding())
cout<<”Outrange\n”;
}
bioskey(0);
return 0;
}
Програма 22.4
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
///////////////
class Base
{public:
~Base()
// virtual ~Base()
{cout<<”Base remove\n”;}
};
////////////
class Derv:public Base
{public:
~Derv()
{cout<<”Derv remove\n”;}
};
/////////////
Int main()
{clrscr();
Base* pBase=new Derv;
delete pBase;
bioskey(0);
return 0;
}
Програма 22.5
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
class Parent
{protected:
int basedata;
};
//////////////
class Child1:virtual public Parent // успадковує копію Parent
{ };
/////////////
class Child2:virtual public Parent //успадковує копію Parent
{ };
///////////
class GrandChild:public Child1,public Child2
{public:
int getdata()
{return basedata;}//так можна
};
///////////////
Int main()
{clrscr();
bioskey(0);
return 0;
}
Програма 22.7
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
class beta;
/////////////
class alpha
{private:
int data;
public:
alpha():data(3) { } // конструктор без аргументів
friend int frifunc(alpha,beta);
};
////////////
class beta
{private:
int data;
public:
beta():data(5) { } //конструктор без аргументів
friend int frifunc(alpha,beta);
};
////////////
int frifunc(alpha a,beta b)
{
return a.data+b.data;
}
///////////
Int main()
{clrscr();
alpha aa;
beta bb;
cout<<frifunc(aa,bb)<<endl;
bioskey(0);
return 0;
}
Програма 22.8
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
class Distance
{int feet;
float inches;
public:
Distance():feet(0),inches(0.0)
{}
Distance(float fltfeet)
{feet=(int)fltfeet;
inches=12*(fltfeet-feet);
}
Distance(int ft,float in)
{feet=ft;inches=in;}
void showdist()
{cout<<feet<<”\’-“<<inches<<’\’’;}
friend Distance operator+(Distance,Distance);
};
//////////////
Distance operator+(Distance d1,Distance d2)
{int f=d1.feet+d2.feet;
float i=d1.inches+d2.inches;
if(i>=12.0)
{i-=12.0;f++;}
return Distance(f,i);
}
//////////////
Int main()
{clrscr();
Distance d1=2.5;
Distance d2=1.25;
Distance d3;
cout<<”\nd1=”;d1.showdist();
cout<<”\nd2=”;d2.showdist();
d3=d1+10.0;
cout<<”\nd3=”;d3.showdist();
d3=10.0+d1;
cout<<”\nd3=”;d3.showdist();
cout<<endl;
bioskey(0);
return 0;
}
Програма 22.10
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>
class Distance
{int feet;
float inches;
public:
Distance():feet(0),inches(0.0)
{}
Distance(float fltfeet)
{feet=(int)fltfeet;
inches=12*(fltfeet-feet);
}
Distance(int ft,float in)
{feet=ft;inches=in;}
void showdist()
{cout<<feet<<”\’-“<<inches<<’\’’;}
float square();
};
//////////////
float Distance::square()
{float fltfeet=feet+inches/12;
float feetsqrd=fltfeet*fltfeet;
return feetsqrd;
}
//////////////