Answer to Question #340207 in C++ for nana

Question #340207

4. Create a program that will plot the equation of the line y=mx+b using an array.


array1 ==> x - input by user


m = constant - input by user


b = constant - input by user


array2 ==> y - computed

1
Expert's answer
2022-05-12T08:20:04-0400
#include <iostream>
using namespace std;


int main(){
	float y[100], m, x[100], b;
	int i, n;
	
	cout << "Enter m: ";
	cin >> m;
	cout << "Enter b: ";
	cin >> b;
	cout << "How many X do you want to enter? ";
	cin >> n;
	for (i = 0; i < n; i ++){
		if (i == 0){
			cout << "Enter first X: ";
		}
		else{
			cout << "Enter the following X: ";
		}
		cin >> x[i];
	}
	cout << "#################################" << endl;
	cout << "#    y = mx+b  --> y = " << m << "x + " << b << "   #" << endl;
	cout << "#################################" << endl;
	cout << "#     X         #       Y       #" << endl;
	cout << "#################################" << endl;
	for (i = 0; i < n; i++){
		cout << "#    " << x[i] << "\t\t#      " << m*x[i]+b << "\t#" << endl;
	}
	cout << "#################################" << endl;


	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS