
- •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()
7)Вычислить комплексное число с помощью формулы Эйлера
#include <iostream.h>
#include <math.h>
class cpx
{
private:
double re; //Действительная часть
double im; //Мнимая часть
public:
cpx() {}; //Конструктор (по умолчанию)
//Сам конструктор
cpx(double r, double i) { re = r, im = i; }
~cpx() {} //Деструктор
double zq() //Возвращаем число r=sqrt(a^2+b^2)
{return sqrt(re * re + im * im);}
double real() //Возвращаем действительную часть
{return re;}
double image() //Возвращаем мнимую часть
{return im;}
//Перегрузка << для класса cpx
friend ostream &operator<<(ostream &, cpx &);
//Перегрузка >> для cpx
friend istream &operator>>(istream &, cpx &);
};
//Перегрузка оператора <<
ostream &operator<< (ostream &fo, cpx &fp)
{
if (fp.im < 0) fo << fp.re << "+i(" << fp.im << ")\n";
else fo << fp.re << "+i" << fp.im << "\n";
return fo;
}
//Перегрузка оператора >>
istream &operator>>(istream &fi, cpx &fp)
{
cout << "Inpit double part: ";
fi >> fp.re;
cout << "Input cpx part: ";
fi >> fp.im;
return fi;
}
Void main()
{double m,fi;//Значение m комплексного числа, и fi - угол, равный arcsin(b/r).
char y;//Проверка не желает ли пользователь вычислить ещё одно число.
y='y';
cpx cq;//cq класса cpx - комплексное число
while (y=='y')
{cin >> cq;
cout<<"\nEntered cpx value z = "<<cq.real()<<" + i*"<<"("<<cq.image()<<")"<<"\n";
fi=asin(cq.image()/cq.zq());//Вычисляется угол fi.
if (cos(2*fi)>=0) m=cq.zq()*sqrt(cos(2*fi));
else m=cq.zq()*sqrt(-cos(2*fi));
cout<<"\nImagine cq in the r-fi form: ";
cout<<"r*(cos(fi) + i*sin(fi))"<<"\n"<<"Where r=sqrt(a*a+b*b) and fi=arcsin(b/r)\n";
cout<<"\nz="<<cq.zq()<<"*"<<"(cos("<<fi<<") + i*sin("<<fi<<"))\n";//Представление комплексного
cout<<"Value of z = "<<m<<"\n\n";//числа в тригонометрическом виде и вычисление его значения
cout<<"Another imaginary quantity? (y/n)";
cin>>y;
cout<<"\n";
}
}
8)Вычислить время через определенный промежуток времени
#ifndef DTIME_H
#define DTIME_H
#include <iostream>
using namespace std;
namespace MyNameSpacedtime {
class DigitalTime{
public:
friend bool operator ==(const DigitalTime& time1,const DigitalTime& time2);
DigitalTime(int the_hour, int the_minute);
DigitalTime();
void advance (int minutes_added);
void advance (int hours_added, int minutes_added);
friend istream& operator >>(istream& ins, DigitalTime& the_object );
friend ostream& operator <<(ostream& outs, const DigitalTime& the_object );
private:
int hour;
int minute;
};
}
#endif
#include<iostream>
#include<cctype>
#include<cstdlib>
#include "dtime.h"
using namespace std;
namespace MyNameSpacedtime{
void read_hour(istream& ins, int& the_hour);
void read_minute(istream& ins, int& the_minute);
int digit_to_int(char c);
//перегрузка оператора ==//
bool operator ==(const DigitalTime& time1,const DigitalTime& time2){
return (time1.hour == time2.hour && time1.minute == time2.minute);
}
//проверка ввода//
DigitalTime::DigitalTime(int the_hour, int the_minute){
if(the_hour <0 || the_hour>23 || the_minute <0 || the_minute >59){
cout<<"no argyment";
exit(1);
}
else {
hour = the_hour;
minute=the_minute;
}
}
DigitalTime::DigitalTime(){
hour=0;
minute=0;
}
//функция прибпвить минуты//
void DigitalTime::advance(int minutes_added){
int gross_minutes=minute+minutes_added;
minute=gross_minutes%60;
int hour_adjustment=gross_minutes/60;
hour=(hour + hour_adjustment)%24;
}
//ф=ия прибавить часы//
void DigitalTime::advance(int hour_added, int minutes_added){
hour=(hour + hour_added)%24;
advance(minutes_added);
}
istream& operator >>(istream& ins, DigitalTime& the_object){
read_hour(ins, the_object.hour);
read_minute(ins, the_object.minute);
return ins;
}
ostream& operator <<(ostream& outs, const DigitalTime& the_object){
outs <<the_object.hour<<':';
if(the_object.minute<10)
outs<<'0';
outs<<the_object.minute;
return outs;
}
// Возвращает целое число указанной цифре.//
int digit_to_int(char c){
return (int(c)-int('0') );
}
void read_hour(istream& ins, int& the_hour){
char c1, c2;
ins>>c1>>c2;
if(!((c1) && ((c2) || c2 == ':' ))){
cout<<"bed znahenie";
exit(1);
}
if (isdigit(c1) && c2 ==':'){
the_hour = digit_to_int(c1);
}
else{//(isdigit(c1) && isdigit(c2))
the_hour = digit_to_int(c1)*10 + digit_to_int(c2);
ins>>c2;
if(c2!=':'){
cout<<"no znahenie";
exit(1);
}
}
if(the_hour <0 || the_hour >23){
cout<<"no znahenie";
exit(1);
}
}
void read_minute(istream& ins, int& the_minute){
char c1, c2;
ins>>c1>>c2;
if(!(isdigit(c1) && isdigit(c2))){
cout<<"no znahenie";
exit(1);
}
the_minute= digit_to_int(c1)*10 + digit_to_int(c2);
if(the_minute<0 || the_minute>59){
cout<<"no znahenie";
exit(1);
}
}
}
#include <iostream>
#include "dtime.h"
int main(){
using namespace std;
using namespace MyNameSpacedtime;
DigitalTime clock, old_clock;
cout<<"vvedite vremja v 24-chasovyx oboznazenijax:";
cin>>clock;
old_clock=clock;
clock.advance(15);
if(clock==old_clock)
cout<<"Chto-to ne tak.\n";
cout<<"Vy vveli"<<old_clock<<endl;
cout<<"Cherez 15 min budet"<<clock<<endl;
clock.advance(2,15);
cout<<"Cherez 2 chasa i 15 minut posle etogo\n"<<"budet"<<clock<<endl;
return 0;
}