Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Progi / Lesson 8 / 8

.3.txt
Скачиваний:
28
Добавлен:
28.03.2015
Размер:
1.48 Кб
Скачать
// laba1.cpp: определяет точку входа для консольного приложения.
//

#include "StdAfx.h"
#include <iostream>
#include <windows.h>

using namespace std;


class Drobi
 {
 public:
  int Getchis();         
  int Getznam(); 
  double Dell(); 
  
  void Init(int m,int s);
  void Read();
  void Display();

  Drobi sloj(Drobi a,Drobi b);
 private:
  int    chis;
   int    znam;

 };



void Drobi::Init(int m,int s)
{
 chis=m;
 znam=s;
}

int Drobi::Getchis()
{
 return chis;
}

int Drobi::Getznam()
{
  return znam;
}

double Drobi::Dell()
 {
	double n;
	int k;
	if((znam==0) && (chis==0)){ throw "bad numbers"; }
	k=chis/znam;
	n=(1.0*chis/znam);
	return n-k;
}


Drobi Drobi::sloj(Drobi a,Drobi b)
{
  Drobi c;         
  c.chis=a.chis*b.znam + a.znam*b.chis;
  c.znam=a.znam*b.znam;
  return c;
}

void Drobi::Read()
{
  cin>>chis>>znam;
}

void Drobi::Display()
{
 // cout<<chis<<znam;
	printf("\n%d/%d\n", chis, znam);
}

int main()
{

 setlocale(LC_ALL, "Russian"); /*setlocale( LC_CTYPE, ".1251" ); */
      

 int m,s;
 double k;
 Drobi x,y,z;
 x.Read();
 y.Init(4,5);

 try{ 
	 k=x.Dell(); 
 }
 catch (char *s)  // ловить только исключение - строку
	{
		cout << " \n WRONG!!!!";
		cout << '\n';
	}
 printf("%.2f\n", k);

 z=z.sloj(x,y);
 z.Display();
 m=z.Getchis();
 s=z.Getznam();
 cout<<endl;

 //cout<<m<<"/"<<s<<endl;

   system("pause");
	  return 0;
   
}

Соседние файлы в папке Lesson 8