0% found this document useful (0 votes)
661 views

Assignment 1 in Computer Programming

The document contains the answers to 10 questions about variable declarations and assignments in C++. It defines several variables of types int and double, initializes some in their declarations, and provides code for assignment statements involving multiplication, addition, subtraction, and computing the area of a rectangle. All questions are answered correctly according to C++ syntax and semantics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
661 views

Assignment 1 in Computer Programming

The document contains the answers to 10 questions about variable declarations and assignments in C++. It defines several variables of types int and double, initializes some in their declarations, and provides code for assignment statements involving multiplication, addition, subtraction, and computing the area of a rectangle. All questions are answered correctly according to C++ syntax and semantics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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