#include <iostream>
using namespace std;
#include <cmath>
double polar (double &, double &);
int main ()
{
double r, angle;
cout << "Enter two numbers for polar coordinates: " << endl;
cin >> r, angle;
polar (r, angle);
cout << "The corresponding rectangular coordinates are (" << x << ", " << y << ")"
return 0;
}
double polar (double & r, double & angle)
{
double x, y;
x = r* cos (angle);
y = r * sin (angle);
return x, y;
}
Hint. Pass by value those things you don't want/need to change in the function and pass by reference those things you do want/need to change. How many variables altogether do you need to pass to your function? What data type does it need to return?
B
Shannon,
Have you covered the C/C++ keyword 'struct' in class yet?
You must use reference parameters to return two values.
Break the problem down.
You need to pass r and angle. Do you need to change their values? You also need to return x and y, both doubles. How might you do that if the function can only return a single value?
B
The problem statement says:
So I would guess no.
B
and return two numbers, x and y, according to the following formula: y = r sin theta, x = r cos theta
Does anything in the formula imply the need to change either 'r' or 'theta'?
mmm no i guess not? i dont really understand reference parameters but im tryyyying
So have we found out a program that allows a Mac to run C++, because when I get into coding I want to know if I will have to buy a PC or not. I love Macs and I hope Apple starts making them more compatible with things.
Were you given any examples of using pass by reference?
Thanks ill download that. and yeah I already have Xcode and I have only used it about 2 times.This is what I used: https://github.com/kennethreitz/osx-gcc-installer
Or you can download xcode, you definitely won't need to buy a PC.
----------
no not really just a comparison between pass by reference and pass by value that makes minimum sense. i dont get anything out of lecture, i learn everything in lab because my lab instructor knows what she is talking about, but sadly this assignment is due before the correspondng lab.
Thanks ill download that. and yeah I already have Xcode and I have only used it about 2 times.
void give_me_a_number(int & number)
{
number = 5;
}
int number_given;
give_me_a_number(number_given);
std::cout << "I was given the number: " << number_given << "\n";
oops and ok good. i wasn't sure if Xcode could code C++If you have Xcode you already have gcc/clang and can compile C++. No need to download install anything else.
B
what are you not able to do?i feel so lost and discouraged now i thought things were going so well. its so frustrating not to be able to do something
what are you not able to do?
Xcode vs GCC? which one is better?
im going to stick with Xcode. by the way, does anyone use Coda here?Xcode is an IDE, gcc is a collection of compilers (gcc = GNU compiler collection) that is used by some versions of Xcode. The newest versions of Xcode are migrating to clang instead of gcc.
B