Monday, July 27, 2009

Help with C++ Programing- Declarations and Identifiers.?

I need help with: Declarations and identifiers. The assignment is: Add declarations using appropriate identifiers for the values below. Declare e, the speed of light, and the speed of sound as constants. initialize the variables. Use any identifier you want for those values that give you no indication as to their purpose.





100 - e (2.7182818)


-100 - speed of light (3.00 x 108 m/s)


-40,000 - speed of sound (340.292 m/s)


40,000 - nothing given





I wasnt in class and its due soon and the teacher has no exceptions. If anyone can help out it would be GREATLY APPRECIATED!

Help with C++ Programing- Declarations and Identifiers.?
If I was initializing e, the speed of light, and the speed of sound as constants, I would simply write:





const double E = 2.71828;


const int SPEED_OF_LIGHT = 300000000;


const double SPEED_OF_SOUND = 340.292;





I guess you're supposed to declare variables for 100, 100, -40000, 40000, and "nothing given"? If that's the case then you can write something like this:





int x1 =100;


int x2 = -100;


int x3 = -40000;


int x4 = 40000;





For the one that says "nothing given", you don't have to initialize; just declare a variable.





You don't have to use x1, x2,... and so on. As the question stated, you can use whatever identifier you want for those values that give you no indication as to their purpose. But keep in mind you can't have an identifier that begins with a number or has any other special characters in it besides an underscore.


No comments:

Post a Comment