0% found this document useful (0 votes)
3 views4 pages

PBA CS HSSC-II Paper C

The document outlines a Computer Science examination for HSSC-II students at Punjab Colleges Rawalpindi/Islamabad, featuring programming tasks in C++. It includes questions on creating a geometry calculator, calculating average and highest temperatures from user input, and defining a student class to compute average marks. Additionally, it requires rewriting code using if-else statements and analyzing the output of a given C++ program.

Uploaded by

Ali Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

PBA CS HSSC-II Paper C

The document outlines a Computer Science examination for HSSC-II students at Punjab Colleges Rawalpindi/Islamabad, featuring programming tasks in C++. It includes questions on creating a geometry calculator, calculating average and highest temperatures from user input, and defining a student class to compute average marks. Additionally, it requires rewriting code using if-else statements and analyzing the output of a given C++ program.

Uploaded by

Ali Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PUNJAB COLLEGES RAWALPINDI/ISLAMABAD

Computer Science HSSC-II PBA


Candidate Name. _____________ Section: _____________ Roll No. ___________________

Section-A [Marks:15]
Question No.1:

Write a C++ program that displays the following menu: [8 marks]

Geometry Calculator

1. Display Area of Circle


2. Display Area of Rectangle
3. Display Area of Triangle
4. Quit

Enter your choice (1-4):

• If user enters 1, the program should ask for the radius of the circle and then display its area. Use
formula: area = πr²
• If user enters 2, the program should ask for the length and width of the rectangle and then displays
its area. Use formula: area = length x width
• If user enters 3, the program should ask for the length of the triangle's base and its height, and then
display its area. Use formula: area = 0.5 * base * height
• If user enters 4, the program should end
• Display an error message if the user enters a number outside the range of 1 through 4.
a. Write down a program using any suitable selection structure. [5]
b. Which selection structure do you think is more appropriate and state the reason? [3]

Answer:

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

Question No. 2: [7 marks]

Write a C++ program that lets the user enter the temperature of the week into an array. The program
should calculate and display average temperature of the week and highest temperature of the week.
• Using and reading correct type of data: [2 marks]
• Correct usage of calculation: [3 marks]
• Correct usage of input/output statement: [2 marks]

Answer:
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

Section-B [Marks:10]

Question No. 3:

Write a program to create a class named “student” and calculate the average marks of three subjects.
[5 Marks]

Answer:

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

Question No. 4: Solve the following table [5 Marks]

No. Questions Answer:


(i) Rewrite the following code using if-else statement:

value = a>b ? a+b : a-b;

(ii) Find the output of the following error-free code if


the user enters a value 4799.

#include<iostream.h>
#include<conio.h>

void main()
{
int no, res=0, r, n;
cout<<"Enter any positive number";
cin>>n;
no=n;
while(no>0)
{
r=no%10;
res=res*10+r;
no=no/10;
}
cout<<"\n The Result of "<<n<<" is "<<res<<" \n";
getch();
}

You might also like