⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cerc.cpp

📁 descriere descriere descriere
💻 CPP
字号:
#include "Cerc.h"
#include <iostream.h>
#include "Punct.h"
#define pi 3.14159
#include <fstream.h>
#include <string.h>
#include <stdio.h>



Cerc::Cerc()
{
   centru.coord_x=centru.coord_y=0;
	tip='c';
   raza = 0;
}
Figura& Cerc::deplasare(double x, double y) 
{
	centru.coord_x+=x;
	centru.coord_y+=y;
	return *this;
}


Cerc::Cerc(Punct c, double r) 
{
	tip='c';
    centru = c;
    raza = r;
}
void Cerc::setRaza(double  r)
{
   raza = r;
}
double Cerc::getRaza()
{
   return raza;
}

double Cerc::Arie()
{
     return (pi*(this->raza)*(this->raza));
}
double Cerc::Perimetru()
{
     return (2*pi*this->getRaza());
}

void Cerc::readFromFile(char* file)
{
    ifstream input(file);
    int x, y;
    double r;
    char c;
	bool read=false;
	
	while(read != true )
	{
		
		if(input.eof()==1)
			break;	

		input>>c;
		if(c=='c')
		{						
			input>>x>>y>>r;		
			read=true;
		}
		else
		{		
			input.ignore(99999,'\n');						
		} 
		
	}             
         centru.muta(x,y);         
         raza = r;
}

      
void Cerc::afisare()
{
    cout<<"originea cercului este: ("<<centru.coord_x<<","<<centru.coord_y<<")"<<endl;
    cout<<"Raza cercului este: "<<raza<<endl;
    cout<<"Perimetrul cercului este: "<<this->Perimetru()<<endl;
    cout<<"Aria cercului este: "<<this->Arie()<<endl;
}

Punct Cerc::getCentru()
{
	return centru;
}
ifstream&  operator>>(ifstream& input,Cerc& cerc)
{	

	int x, y;
    double l;
    char c;
	bool read=false;
	
		


	while(read != true )
	{
		
		if(input.eof()==1)					
			break;	

		input>>c;	
		if(c=='c')
		{		
			input>>x>>y>>l;
		}
		else
		{
			input.ignore(9999,'\n');
		}
	}			
			
	cerc.centru.muta(x,y);
	cerc.raza=l;

	return input;
}


ofstream& operator<<(ofstream& out,Cerc& cerc)
{
	out<<"Cerc "<<endl<<"Raza "<<cerc.getRaza()<<endl;
	out<<"Originea "<<"X: "<<cerc.centru.coord_x<<endl<<"Y: "<<cerc.centru.coord_y<<endl;
	return out;
}

istream&  operator>>(istream& input,Cerc& cerc)
{	

	int x, y;
    double r;
   
	input>>x>>y>>r;			
	cerc.centru.muta(x,y);
	cerc.raza = r;
	return input;
}

ostream& operator<<(ostream& out,Cerc& cerc)
{
	out<<"Cerc "<<endl<<"Raza "<<cerc.getRaza()<<endl;
	out<<"Originea "<<"X: "<<cerc.centru.coord_x<<endl<<"Y: "<<cerc.centru.coord_y<<endl;
	return out;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -