C++传智笔记:C++完整demo

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++传智笔记:C++完整demo相关的知识,希望对你有一定的参考价值。

MyPoint.h
#pragma once
class MyPoint
{
private:
	double x0, y0; //点坐标
public:
	void setPoint(double x, double y);
	double getX0();
	double getY0();
};
MyPoint.cpp
#include "MyPoint.h"

void MyPoint::setPoint(double x, double y)
{
	x0 = x;
	y0 = y;
}
double MyPoint::getX0()
{
	return x0;
}
double MyPoint::getY0()
{
	return y0;
}
MyCircle.h
#pragma once
#include "MyPoint.h"
class MyCircle
{
public:
	void setCir(double x, double y, double r);
	
public:
	char * judge(double x, double y);
	char * judge(MyPoint &p);

private:
	double x1, y1; //?2D?×?±ê
	double r1;  //?2°???
};
MyCircle.cpp
#include "MyCircle.h"

void MyCircle::setCir(double x, double y, double r)
{
	//这里面也是类的内部
	x1 = x; y1 = y; r1 = r;
}
char* MyCircle::judge(double x, double y)
{
	double s = (x1-x)*(x1-x) + (y1-y)*(y1-y) - r1*r1 ;
	if (s > 0)
	{
		return "在圆外";
	}
	else
	{
		return "在圆内";
	}
}
char* MyCircle::judge(MyPoint &p)
{
	double s = (x1-p.getX0())*(x1-p.getX0()) + (y1-p.getY0())*(y1-p.getY0()) - r1*r1 ;
	if (s > 0)
	{
		return "在圆外";
	}
	else
	{
		return "在圆内";
	}
}

  main.cpp

#include "iostream"
using namespace std;

#include "MyCircle.h"
#include "MyPoint.h"

void main()
{
	MyCircle c1;
	MyPoint  p1;

	c1.setCir(2, 2, 3);
	p1.setPoint(1, 1);
	cout<<c1.judge(p1.getX0(), p1.getY0())<<endl;
	cout<<c1.judge(p1)<<endl;
	system("pause");

}

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

以上是关于C++传智笔记:C++完整demo的主要内容,如果未能解决你的问题,请参考以下文章

低价好课:全网最全2014传智播客C++全年整合版(285GB)百度云高清完整

C++ 异步编程笔记 (ISO C++ 17)

《C++ Primer中文版(第5版)》学习笔记与习题完整发布!

算法笔记 排序算法完整介绍及C++代码实现 HERODING的算法之路

LeetCode 热题 HOT 100 完整题解笔记&知识点分类 C++代码实现

剑指 Offer(第 2 版)完整题解笔记 & C++代码实现(LeetCode版)