Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
You need to do a converion of something from degrees angle to radians!

Code:
double degree2radian(double radian)
{
	return ((radian * 3.14159265) / 180);
}
 
sorry forbeing so dumb, what could be wrong with my cin? this is the program from hell.

edit:

is this why im getting this warning?
polar.cpp:15:12: warning: expression result unused [-Wunused-value]
cin >> r, angle;

I'll put some parentheses around it so you can see more clearly what this means:

Code:
(cin >> r), (angle);

The whole thing is an expression statement - an expression statement is a statement consisting of an expression, followed by a semicolon.

The expression consists of two parts, separated by a comma. That's called a "comma expression". In a comma expression, first the part left of the comma is evaluated, the result thrown away, then the right part is evaluated.

The left part is (cin >> r), and the right part is (angle). Evaluating the left part has the side effect of reading data from cin and putting the result into r. Evaluating the right part just takes the value of the variable "angle" and does nothing with the result.

The total effect of this expression statement is exactly the same as if you had used two statements:

Code:
    cin >> r;
    angle;

where the second expression statement just evaluates angle and does nothing with the result.
 
oh my god i am an idiot.
i knew that. i totally knew that i just didnt see it. i want to punch myself in the face right now.

----------

now my output is correct, except instead of 3.19531, 1.42829 i get the reverse.

is that just because i opted to output x before y? or is it evidence of a huge mess up? lol
 
Shannon,

When you find yourself flustered and confused, like now, it's best to take a break of at least 15 minutes, do something that doesn't require much thinking, and come back to the problem.

Banging your head against the wall for hours, noting it hurts and banging your head against the wall some more is kind of crazy.
 
now my output is correct, except instead of 3.19531, 1.42829 i get the reverse.

is that just because i opted to output x before y? or is it evidence of a huge mess up? lol

Assuming that is the answer the prof. expected the angle is 20 radians, not 20 degrees. That seems a bit wacky as it is 6 full rotations and 65.9 degrees left over.

B
 
Shannon,

When you find yourself fluster and confused, like now, it's best to tale a break of at least 15 minutes, do something that doesn't require much thinking, and come back to the problem.

Banging yoir head against the wall for hours, noting it hurts and banging your head against the wall some more is kind crazy.
lol my heads about to explode. i think its finally done though, so im turning off the homework brain. been doing assignments since 10am. it is now 10pm. ouch. anyway so i think we're set here.. are we not?? did i finally accomplish the impossible?

----------

Assuming that is the answer the prof. expected the angle is 20 radians, not 20 degrees. That seems a bit wacky as it is 6 full rotations and 65.9 degrees left over.

B

i dont know what he expects half the time. im really upset with the way hes conducting the class. but the sample output is showing what i get when i input the sample input, so that is a good sign right?
 
Code:
#include <iostream>
using namespace std; 
#include <cmath>

void polar (double &, double &, double, double);

int main ()
{
	double x;
	double y; 
	double r; 
	double angle;
	
	cout << "Enter two numbers for polar coordinates: ";
	cin >> r, angle; 

	polar (x, y, r, angle);

	cout << "The corresponding rectangular coordinates are (" << x << ", " << y << ")" << endl;
	
	return 0; 
}

void polar (double & x, double & y, double r, double angle) 
{
	x = r * cos(angle);
	y = r * sin(angle);
	
}

thanks for your patience :D:D:D
You want to split that into a .cpp and a header file. The header files contain the function and method definitions:
pol2rect.h:
Code:
#include <iostream>
#include <cmath>

[url=http://www.cplusplus.com/doc/tutorial%20%20/preprocessor/]#define[/url] DEG2RAD(DEG) ((DEG)*((3.14159265358979323846)/(180.0))) 
void polar2rectangular(double &, double &, double, double);
while the cpp (.cpp and .h should have the same name) contains the implementation:
pol2rect.cpp:
Code:
#include "pol2rect.h"

void polar2rectangular(double & x, double & y, double r, double angle) 
{
	x = r * cos(angle);
	y = r * sin(angle);
	
}

int main ()
{
	double x, y, r, angle;
	
	std::cout << "Enter the radius: ";
	std::cin >> r;
	std::cout << "Enter the the angle: ";
	std::cin >> angle; 

	polar2rectangular(x, y, r, DEG2RAD(angle));

	std::cout << "The corresponding rectangular coordinates are (x=" << x << ", y=" << y << ")" << std::endl;
	
	return 0; 
}
It still compiles the same way:
Code:
g++ -Wall pol2rec.cpp -o pol2rec

And don't use using namespace std;, it's bad.
 
Last edited:
Hey guyssss.. so my exam is this coming thursday, and the major topics (that are actually confusing me) that are on it are arrays and classes.. does anyone know of a concise, easy to understand website that I could refer to in my studying?
 
Hey guyssss.. so my exam is this coming thursday, and the major topics (that are actually confusing me) that are on it are arrays and classes.. does anyone know of a concise, easy to understand website that I could refer to in my studying?

What is your confusion on them?

Let me see if I can help explain in some basic terms.

Arrays:

An array is basically a large ordered list of data types. For example say I wanted to store a series of five names:

Scott
Justin
Mirsad
Jen
Liz

These names are all strings so I could do something like this:

name0 = "Scott"
name1 = "Justin"
name2 = "Mirsad"
name3 = "Jen"
name4 = "Liz"

but that is insanely inefficient. Instead I can create a string array, that holds an amount of strings that I want:

string name[5];

Then I can do:

name[0] = "Scott";
name[1] = "Justin";
name[2] = "Mirsad";
name[3] = "Jen";
name[4] = "Liz";

Now, if I want to access them, I can write something like:

cout << "The first element in the array is: " << name[0] << endl;

An easier way to get all of the names in an array would be to initialize them like this:

string name[5] = {"Scott", "Justin", "Mirsad", "Jen", "Liz"};

I could then access them the same way:

cout << "The third element in the array is: " << name[2] << endl;

Remember, arrays are zero based so when I have five names, they start at zero (which is why name[2] access the third element in the array).
 
thanks :)

right now, i'm having a hard time understanding the public/private things for classes, and what exactly a constructor is?

i think arrays are a bit more clear to me now because ive been studying them a lot more the past few days.

im so nervous! the exam is worth 45%, i already passed the class because i have like a 50/55 but id love to do really well on this exam!

----------

It's been a whole month since your last post so I'm not really sure where you're at and what you've covered since then.

Perhaps an update ...

i'll try to give a more concise updated tomorrow when im looking through my notes and can pinpoint exact things :)
 
Passing with 50/100 means a decent curve(maybe not huge if 60% is a D).

Anyway... accessibility (public/private/protected) controls access to member variables and functions from other code/classes.
public: go nuts. Anyone can get to this.
private: only instance methods can modify instance variables marked private.
protected: other instances of this class and instances of friends of this class can access this.

A constructor is code that runs when a new instance of a class is created. You can have many of these with different arguments (just like overloading other methods). This lets you setup your instance when it is created and get it ready to use.

-Lee
 
Hey Yallll..
I got my final mark for c++ today :)
82 on the final which meant 88 over all the in the class but he scaled them so my final mark is a 90!!! i can live with that.. thanks for your help everybody! i did it!! :D :cool:
 
Well, congratulations!

We see so many students pass thru here never to be heard from again. In your case I see you've checked back since your last post so thought I'd ask a couple of questions.

What are you going to school for?

Have you enjoyed any of your programming experience?

Do you still fear tackling problem solving?


Good luck.
 
Well, congratulations!

We see so many students pass thru here never to be heard from again. In your case I see you've checked back since your last post so thought I'd ask a couple of questions.

What are you going to school for?

Have you enjoyed any of your programming experience?

Do you still fear tackling problem solving?


Good luck.

Haha, I'm doing a Bachelor of Science and plan to do something medical related (probably Pharmacy)

I don't think it would be something I'd take another class on, but it's kind of cool to have that experience under my belt and actually come out with some new knowledge!

and Yes, I do still fear tackling problem solving :p
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.