编一个程序,画出以下抛物线

①y=2x^2 ②y=2x^2-1 ③y=2(x-1)^2+1  ④2(x+1)^2-1

运行结果:

不考虑效率的话很简单,直接上代码:

#include "pch.h"
#include <iostream>
#include"graphics.h"
void zbz(int x) {
	line(x-50,350, x+50, 350);
	line(x, 250, x, 370);
}
void pw1() {
	double x = 0, y = 0;
	zbz(900);
	for (int i = 0; i < 100; i++) {
		if (i <2) {
			y = 0.05 * x * x;
			putpixel((int)x + 900, -((int)y) + 350, WHITE);
			putpixel(-(int)x + 900, -((int)y) + 350, WHITE);
			x += 1;
		}
		else {
			x = sqrt(y /0.05);
			
			putpixel((int )x+900 ,- ((int)y) + 350, WHITE);
			putpixel(-(int)x +900, -((int)y) + 350, WHITE);
			y++;
		}
	}
	outtextxy(900, 400, '1');
}

void pw2() {
	zbz(700);
	double x = 0, y = 0;
	for (int i = 0; i < 100; i++) {
		if (i < 10) {
			y = 0.05 * x * x-5;
			putpixel((int)x +700, -((int)y) + 350, WHITE);
			putpixel(-(int)x + 700, -((int)y) + 350, WHITE);
			x += 1;
		}
		else {
			x = sqrt((y +5)/ 0.05);

			putpixel((int)x + 700, -((int)y) + 350, WHITE);
			putpixel(-(int)x + 700, -((int)y) + 350, WHITE);
			y++;
		}
	}
	outtextxy(700,400, '2');
}
void pw3() {
	zbz(500);
	double x = 0, y = 0;
	for (int i = 0; i < 100; i++) {
		if (i < 20) {
			y = 0.05 * (x-10) * (x - 10)+10;
			putpixel((int)x + 500, -((int)y) + 350, WHITE);
		//	putpixel(-(int)x + 500, -((int)y) + 350, WHITE);
			x += 1;
		}
		else {
			x = sqrt((y - 10) / 0.05)+10;

			putpixel((int)x + 500, -((int)y) + 350, WHITE);
			putpixel(-(int)(x-20) + 500, -((int)y) + 350, WHITE);
			y++;
		}
	}
	outtextxy(500, 400, '3');
}
void pw4() {
	zbz(300);
	double x = -10, y = 0;
	for (int i = 0; i < 100; i++) {
		if (i <10) {
			y = 0.05 *( x +10)*( x +10)-10;
			putpixel((int)x + 300, -((int)y) + 350, WHITE);
			putpixel(-(int)(x+20) + 300, -((int)y) + 350, WHITE);
			x += 1;
		}
		else {
			x = sqrt((y + 10) / 0.05)-10;

			putpixel((int)x + 300, -((int)y) + 350, WHITE);
			putpixel(-(int)(x+20) +300, -((int)y) + 350, WHITE);
			y++;
		}
	}
	outtextxy(300, 400, '4');
}
int main()
{
	initgraph(1000,600);
	pw1();//抛物线2x^2
	pw2();//抛物线2x^2-1
	pw3();//抛物线2(x-1)^2+1
	pw4();//抛物线2(x+1)^2-1
	getchar();
	closegraph();
}