
- •1)Класс массив. Описывает нулевой единичный вектор, нулевой вектор произвольного размера и вектор произвольного размера с произвольными значениями
- •2) Описать скалярное произведение векторов
- •If(!m_pVec){
- •Void main(){
- •3)Записать обыкновенную дробь
- •4)Сумма комплексных чисел
- •Void main(){
- •5)Множественное наследование. Создать класс, произвольный от нескольких базовых
- •6)Работа с множествами
- •7)Вычислить комплексное число с помощью формулы Эйлера
- •Void main()
- •8)Вычислить время через определенный промежуток времени
- •9)Вычислить сумму, разность, произведение матриц
- •Void main()
- •10)Вычисление суммы, разности, произведения и деление комплексных чисел
- •Void main()
- •11)Вычислить радиус, диаметр, длину окружности, площадь и объем сферы
- •12)Работа с шаблонами
- •13)Банковские операции (чековая и сберегательная книжка)
- •Void display()
- •Void display()
- •14)Вычислить сумму векторов
- •15)Сортировка по возрастанию
- •Void main()
10)Вычисление суммы, разности, произведения и деление комплексных чисел
#include <iostream.h>
#include <conio.h>
#include <math.h>
class Complex
{
private:
double real; // Действительная часть
double image; // Мнимая часть
public:
Complex() {}; // Конструктор по умолчанию
Complex(double r, double i) { real = r, image = i; } // Конструктор
~Complex() {} // Деструктор
Complex operator+(Complex &); // Перегрузка оператора сложения
Complex operator-(Complex &); // Перегрузка оператора вычитания
Complex operator*(Complex &); // Перегрузка оператора умножения
Complex operator/(Complex &);
// Перегрузка оператора деления
// Перегрузка функции-оператора << для вывода класса Complex
friend ostream &operator<<(ostream &, Complex &);
// Перегрузка функции-оператора >> для ввода класса Complex
friend istream &operator>>(istream &, Complex &);
};
// Перегрузка +
Complex Complex::operator+(Complex &fp1)
{
fp1.real = real + fp1.real;
fp1.image = image + fp1.image;
return fp1;
}
// Перегрузка -
Complex Complex::operator-(Complex &fp1)
{
fp1.real = real - fp1.real;
fp1.image = image - fp1.image;
return fp1;
}
// Перегрузка *
Complex Complex::operator*(Complex &fp1)
{
double i, j;
i = real * fp1.real - image * fp1.image;
j = real * fp1.image + fp1.real * image;
fp1.real = i;
fp1.image = j;
return fp1;
}
// Перегрузка /
Complex Complex::operator/(Complex &fp1)
{
double k, i, j;
k = fp1.real * fp1.real + fp1.image * fp1.image;
i = (real * fp1.real + image * fp1.image) / k;
j = (fp1.real * image - real * fp1.image) / k;
fp1.real = i;
fp1.image = j;
return fp1;
}
// Перегрузка оператора <<
ostream &operator<< (ostream &fo, Complex &fp)
{
if (fp.image < 0) fo << fp.real << "+i(" << fp.image << ")\n";
else fo << fp.real << "+i" << fp.image << "\n";
return fo;
}
// Перегрузка оператора >>
istream &operator>>(istream &fi, Complex &fp)
{
cout << "Vvedite dejstvitelnuju chast: ";
fi >> fp.real;
cout << "Vvedite mnimuju chast: ";
fi >> fp.image;
return fi;
}
Void main()
{
// Комплексные числа
Complex c1, c2, c3, c4, c5;
// Ввод комплексных чисел
cin >> c1;
cin >> c2;
cin >> c3;
cin >> c4;
cin >> c5;
// Вывод комплексных чисел
cout << "\nc1 = " << c1;
cout << "c2 = " << c2;
cout << "c3 = " << c3;
cout << "c4 = " << c4;
cout << "c5 = " << c5 << '\n';
// Вывод результатов операций
cout << "c1 + c2 = " << (c1 + c2);
cout << "c1 - c3 = " << (c1 - c3);
cout << "c1 * c4 = " << (c1 * c4);
cout << "c1 / c5 = " << (c1 / c5);
}
11)Вычислить радиус, диаметр, длину окружности, площадь и объем сферы
const double PI=3.14158;
class Sphere
{
public:
Sphere();
// Konstructor po umolchaniu: sozdaet sferu
// inicializiruja Radius znacheniem zadannim po umolchaniu
Sphere( double initialRadius);
// Konstructor sozdaet sferu
// inicializiruja Radius zadannim znacheniem
void setRadius( double newRadius);
// Ustanavlivaet (izmeniaet) radius sushestvujushei sferi
double getRadius() const;
// Vichisliaet radius sferi
double getDiametr() const;
//// Vichisliaet diametr sferi
double getCircumference() const;
// Vichisliaet dlinu okrujnosti sferi
double getArea() const;
// Vichisliaet ploshad poverhnosti sferi
double getVolume() const;
// Vichisliaet obiem sferi
void displayStatistics() ;
//Vivodit parametri sferi
private:
double theRadius;
};
#include "Sphere.h" // header file
#include <iostream.h>
Sphere::Sphere():theRadius(1.0)
{
} // end of constrution po umolchaniu)))
Sphere::Sphere( double initialRadius)
{
if (initialRadius>0) theRadius=initialRadius;
else theRadius=1.0;
} // end of constrution
void Sphere::setRadius( double newRadius)
{
if (newRadius>0) theRadius=newRadius;
else theRadius=1.0;
} //end of function-member setRadius
double Sphere::getRadius() const
{
return theRadius;
}//end of function-member getRadius
double Sphere::getDiametr() const
{
return 2*theRadius;
}//end of function-member getDiametr
double Sphere::getCircumference() const
{
return PI*getDiametr();
}//end of function-member getDiametr
double Sphere::getArea() const
{
return 4.0*PI*theRadius*theRadius;
}//end of function-member getArea
double Sphere::getVolume() const
{
double radiusCubed = theRadius*theRadius*theRadius;
return (4.0*PI*radiusCubed )/3.0;
}//end of function getVolume
// inside of function displayStatistics() may call
//function-member getRadius() or used field theRadius
void Sphere::displayStatistics()
{
cout<<"\n Radius= "<<getRadius()
<<"\n Diametr= "<<getDiametr()
<<"\nLenght of Circumference= "<<getCircumference()
<<"\nArea= "<<getArea()
<<"\nVolume= "<<getVolume()<<endl;
}
#include<iostream.h>
#include"Sphere.h"
int main()
{
Sphere initSphere; // Radius =1,0
Sphere mySphere(5.1); // Radius =5.1
mySphere.displayStatistics();
initSphere.displayStatistics();
mySphere.setRadius(4.2);// Ustanavlivaem Radius = 4.2
mySphere.displayStatistics();
return 0;
}