You are on page 1of 2

Assignment 1 in Computer Programming 1

Name: Cantuba III, Cherry D.


Year and Section: DICT 1-5

1. Which of the following may be used as variable names in C++?

Rate1, 1stPlayer, myprogram.java, long, TimeLimit, numberOfTimes

Answer: Rate1, TimeLimit, numberOfTimes

2. Can a C++ program have two different variables with the names aVariable and
avariable?

Answer: Yes.

3. Give the declaration for a variable called count of type int.  The variable should be
initialized to zero in the declaration.

Answer: int count = 0;

4. Give the declaration for two variables of type double.  The variables are to be named
rate and time.  Both variables should be initialized to zero in the declaration.

Answer: double rate = 0, time = 0;

5. Write a declaration for two variables called miles and flowRate.  Declare the variable
miles to be of type int and initialize it to zero in the declaration.  Declare the variable
flowRate to be of type double and initialize it to 50.75 in the declaration.

Answer: int miles = 0;

double flowRate = 50.75;

6.    Write a C++ assignment statement that will set the value of the variable interest to the
value of the variable balance multiplied by 0.08.

Answer: interest = balance * 0.08;

7.    Write a C++ assignment statement that will set the value of the variable interest to the
value of the variable balance multiplied by the value of the variable rate.  The variables
are of type double.

Answer: interest = balance * rate;

8.    Write a C++ assignment statement that will increase the value of the variable count by
3. The variable type is int.

Answer: count = count + 3;

9.    Write a C++ assignment statement that will decrease the value of the variable count by
5.  The variable type is int.
Answer: count = count – 5;

10.  Write a C++ assignment statement that will compute the area of a rectangle.

Answer: area = length * width;

You might also like