Here is what I have to do:
Write a C++ program to "draw" ellipses by printing characters, to the following specifications:
Prompt the user for values for a and b, then draw an ellipse using the formula
(x2/a2)+(y2/b2)=1. Actually, since double values in C++ are rarely exact, use (x2/a2)+(y2/b2)-1.0<0.0001, but use a named constant in place of 0.0001.
Since there are 25 rows in a standard PuTTy screen, output 24 rows for the ellipse. For each row number row 0 to 23, let y be 12-row.
Since there are 80 columns in a standard PuTTy screen, output 80 characters in each line. Since each column is equivalent to about half a row in terms of space, for each column number col 0 to 79, let x be (40-col)/2.
Use pow from <cmath> to calculate the squares, ensuring that the two parameters are of type double.
After the ellipse, output information about it and prompt to repeat or not.
If it is a circle, output the word Circle, the radius of the circle (either a or b), the area of the circle and the number of characters printed in the "drawing", as in the first example.
If it is not a circle, output the word Ellipse, both a and b, the area of the ellips and the number of characters printed, as in the second example.
The area of an ellipse is Π * a * b. Use M_PI from <cmath> for the value of Π.
All floating point numbers should be output in fixed format, always showing the point and with a precision of 2 places after the point.
An example executable named project1 is available in the /share directory on the server.
As with project 1, upload a text file containing a cat of your program file, a compiler instruction and a sample run of your program to this dropbox.
You must include documentation at the top of the program with your name, the date, the course section, and a short description of the program. Every variable must have a comment explaining briefly what it is for.
Here is my Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include<iostream>
#include<cmath>
using namespace std;
const double PI = M_PI;
const double ZERO = 0.0001;
int a, b; //variables for a and b
int Characters; //variable for the number of characters used to create the shape
int runProgram();
int main(){ //main method that uses a do-while loop to repeat the program if the user enters anything besides Y or y at the end.
char Continue;
do{ runProgram();
cout << "Would you like to run again? Enter Y to continue or N to quit." <<endl;
cin >> Continue;
}//End of do
while((Continue!='n')||(Continue!='N'));
} //end of main
int runProgram(){
cout << "Enter a number for 'a' : "; //asks for input a
cin >> a; //inputs number from keyboard to variable a
cout << "Enter a number for 'b' : "; //asks for input b
cin >> b; //inputs number from keyboard to variable b
// drawEllipse(); //method to draw ellipse
// circletest(); //method to output information about the ellipse
// characters(); //method to output the number of characters that the ellipse used
}//End of runprogram
int drawEllipse(){ //method to draw an ellipse
int y=0,x=0,row=0;
for(y=0; y<12-row ; row++ ){
for(x=0; x<80; x++){
if((x*x)/(a*a)+(y*y)/(b*b)-1.0<ZERO);
cout << " " <<endl;else { cout << "@" <<endl;
} //End of else
}//End of for
}//End of for
}//End of draw ellipse
int circletest(){ //tests to see if variable a=b
if (a==b){
cout << "Circle :: " << "radius = " << a << " :: area = " << PI*a*a << " :: " <<endl;
} else {
cout << "Ellipse :: " << "a = " << a << "b = " << b << " :: area = " << PI*a*a << " :: " <<endl;
}//End of else
}
int characters(){
cout << "Characters = " << Characters << endl;
}
|
everything checks out ok, but I keep getting one Error message, and I don't know what to do.
.cpp: In function 'int drawEllipse()':
.cpp:35: error: expected primary-expression before 'else'
.cpp:35: error: expected `;' before 'else'
|
Any Ideas?