wylun Expert Cheater
Reputation: 0
Joined: 27 Jun 2006 Posts: 101
|
Posted: Thu May 14, 2009 2:15 pm Post subject: C++ building a sin() table for calculation |
|
|
Description:
For this assignment, you will be building a sin() table, and then using the sin() table to perform some calculations.
Task:
Create a C++ program that will do the following:
a) Create and initialize a sin() table. The size of this table should be 360, with each element of the table storing the sin() value. Hence, the index into the array represents degrees.
b) Prompt the user for 2 numbers which represents a vector using Polar coordinates.
c) Convert this Polar coordinate into Cartesian coordinate in the following way:
i. Using the sin() table you created, determine the Y-coordinate of this Polar coordinate.
ii. Once you have the Y-coordinate, use Pythagoras’ theorem to determine the X-coordinate.
iii. Output the Cartesian coordinate that you just computed with an appropriate message.
E.g The Polar coordinates you enter 10@30 degrees
has Cartesian coordinates (5, 8.6)
d) The program should repeat this process of allowing the user to input 2 numbers and converting them into Cartesian coordinates. However, if the input numbers are -99, -99, the program should exit with an appropriate message.
| Code: | #include <iostream>
#include <math.h>
using namespace std;
double sin_table[360];
double x, y;
void main()
{
for(int i = 0; i < 360; i++)
{
sin_table[ i ] = sin( i * (3.142/180));
}
float mag, angle;
int st = 5;
do
{
cout << " Please enter -99 into both input to exit the program "<<endl<<endl;
cout << " Please enter 1st number for magnitude :";
cin >> mag;
cout << " Please enter 2nd number for degrees :";
cin >> i;
cout << endl<<endl;
// program will start calculate if both key in not -99
if ( mag != -99 && angle != -99 )
{
// do the calculation here
y = mag * sin_table[ i ];
x = sqrt(pow(mag,2) - pow(y,2));
cout << " The Program will ask for input again in few second "<<endl;
// server as time count down to restart the whole program
for ( int i=0; i<99 ; i++ ){
for (int y=0; y<999 ; y++){
for(int a=0; a<999; a++){};
};};
// screen clear
system("cls");
}
//when the magnitude and angle both equal as -99, the program will go off
} while(mag != -99 && angle != -99);
cout << "y = " << y << endl;
cout << "x = " << x << endl;
cout << "The Cartesian coordinate for the Polar is " << y << "," << x << endl;
cout << "Thank you for using the program " << endl;
cout << "The program going to end now " << endl;
cout << endl;
return;
} |
What is my programme problems? anyone help me pls! Urgent
_________________
OWE REV 791 ,REV800,REV822,REV833
(quit maple) Currently playing MaplePrivateServer. |
|