Home >  T.A >  cs10 ( Fall 2001 ) >  Lab 3

  CS10 Sec#24 : Topics covererd in Lab #3
T.A: Demetris Zeinalipour
(Fall 2001)

Print this Page   
Top


Academic Dishonesty Policy
I will give you a handout on cheating. You must sign this handout and return it to me. If you were not able to attend Lab 2 please make sure that you come and find me in order to sign the sheet (within 2 weeks).
Top


Working with Arithmetic Operators
Write a program that lets the user enter a number of days. Your program should then output convert the given days into years, months, weeks, and days. Use 365 days in one year and 30 days in one month.
For example:

Enter the number of days: 840
// your program would output something like:
840 days is equivalent to:


2 years

3 months

2 weeks

6 days


* Be sure to put all your information (login, lab section, …) at the top of your program. I will be checking off your program during lab to give you points or any help you may need.
* * Also please keep in mind the "Style Considerations" section of Lab 2, because you have to apply again all rules that we have mentioned
Top


C++ Built-In Data Types

Check out the following table of C++ Built-In data types. This wil help you to understand when you should use a particular datatype. Using the correct data type makes our program "faster" and better. In that way we are showing respect to the machine resources. I don't ask you use the following table but if you feel that you want to improve your C++ knowledge you can always use it as a reference.

e.g If I ask you to define a variable for your age you could of course use 'int'. Using 'int' though has an overhead since it range from -2^31 until 2^31 which means that the age variable can have a value between -2,147,483,648 and 2,147,483,647.

Don't you think that this is a too big range for the age field?.

On the other hand is it ever possible that the age field has a negative value?.

Of course not. So you could use 'short age' which would allocate only -32768 until 32767 or you could even better use 'unsigned short age' which would be only 0 until 65535 and which is more than enough to store the age value.


Top