Important Introduction to Programming Short Questions
Chapter: 4
Question 1:
What is the first step in calculating the average age of a class?
Answer:
The first step is to prompt the user to enter the age of each student and store these ages in separate variables.
Chapter: 4
Question 2:
How do you declare variables to store the ages of ten students?
Answer:
Variables can be declared in a single line using the int data type separated by commas, e.g., int age1, age2, age3, ... , age10;.
Chapter: 4
Question 3:
Why do we use the int data type for storing student ages?
Answer:
The int data type is used because we are dealing with whole numbers (e.g., 10, 12, 15) when storing the ages of students.
Chapter: 4
Question 4:
What is the purpose of the TotalAge variable in the program?
Answer:
The TotalAge variable is used to store the sum of all the ages of the students.
Chapter: 4
Question 5:
How is the average age calculated in the program?
Answer:
The average age is calculated by dividing the TotalAge by 10 and storing the result in the AverageAge variable.
Chapter: 4
Question 6:
What will be the issue if AverageAge is declared as int?
Answer:
If AverageAge is declared as int, any decimal portion of the average will be truncated, resulting in an inaccurate value.
Chapter: 4
Question 7:
How does the program prompt the user for input?
Answer:
The program uses the cout statement to display a message like “Please enter the age of student 1: ”, and then uses cin to capture the user's input.
Chapter: 4
Question 8:
How does the program read the age of the first student?
Answer:
The program reads the age of the first student using the statement cin >> age1;.
Chapter: 4
Question 9:
What does the cin object do in the program?
Answer:
cin is an input stream object that reads data from the user and assigns it to the variable on its right side, such as cin >> age1;.
Chapter: 4
Question 10:
What is the significance of the >> operator in cin >> age1;?
Answer:
The >> operator indicates the direction of data flow, assigning the user input from cin to the variable age1.