CSCI 1300
Introduction to Computing


Quiz #1

1.   (10 points each) Write declarations for each of the following:

a. A variable of type double called price

            double price;

b. A variable of type int called age

            int age;

c. A string constant called name that contains your name

            const char name[] = "Scott Brandt";


2.  (10 points each) Given a string s and an integer x

a. Write a C++ expression to print on the screen "s is <whatever s is>",
     followed by a carriage return (i.e. move the cursor to the next line).

            cout << "s is " << s << "\n";

b. Write a C++ expression to get a number from the user and put it into x

            cin >> x;


3.  (10 points each) Given the following definition of the function ceil():

Syntax
#include <math.h>
double ceil(double x);

Description
Rounds up.
ceil finds the smallest integer not less than x.

Return Value
The integer found as a double.

a. What value would you expect to be returned if you executed ceil(2.1)?

            3.0

b. What is the return type of the function ceil()?

            double

c. What include file do we need to include if we want to use the function ceil()?

            math.h


4. (10 points) Write a function that takes as parameters the lengths of the sides of a rectangle and returns the area.

    double area_of_rect(double length, double width)
    {
        double area;
        
        area = length * width;

        return(area)
    }

    or

    double area_of_rect(double length, double width)
    {
        return(length * width);
    }


5.  (10 points) Define a class called Radio that has:
  • Two private variables:
  • volume (an int)
  • frequency (a double)
  • Two public functions
  • set_volume() that takes an int as a parameter and returns nothing
  • scan_up() that takes no parameters and returns a double
  • Note: do not actually write the functions, just give the class definition.

    Now show how you would declare a Radio object, and set its volume to 5.

    
        class Radio {
          private:
            int    volume;
            double frequency;
    
          public:
            void   set_volume(int);
            double scan_up(void);
        };
    
        -----
    
        Radio panasonic;
        panasonic.set_volume(5);