cpp1_code_s08

# cpp1_code_s08 - CGS-2421 C EXAM 1 USERNAME CODING PART...

This preview shows pages 1–3. Sign up to view the full content.

CGS-2421 C++ EXAM 1 CODING PART SPRING 2008 USERNAME ___________________ NAME __________________________________ 1. (15 pts)Write a function called step that implements the following equations: n+1 for n < x <= n+1, n >=0 and an integer f(x) = 0 for x=0 n for n <= x < n+1, n < 0 and an integer Prototype: double step(double x); Examples: double d = step(3.25); -> copies 4 to d cout << step(-2.82); -> prints -3 cout << step(0); -> prints 0 Hint: You may use functions ceil() and floor() in your solution. --------------------------------------------------------- Your Solution ------------------------------------------------------- double step( double x) { if (x>0) return ceil (x); else if (x==0) return 0; else return floor (x); }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
USERNAME ___________________ NAME __________________________________ 2.(15pts) Write a function called temp_conv that converts from celcius (C) to fahrenheit (F). F = (9/5) * C + 32 The function receives the temperature in celcius and determines the temperature in fahrenheit. Since the absolute zero is at -273 C, any input less than -273 C is not valid. The function temp_conv will return false in case of an invalid input and return true if the input is valid. If the input is valid, it will also calculate the corresponding Fahrenheit temperature.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern