Q1: A-Write a C++ to read three numbers and print
their average;
Sol:
#include <iostream>
using namespace std;
void main ( )
{
float x , y
, z ;
float av ;
cout
<< " Enter Three Integer
Values :\n " ;
cin >>
x >> y >>z ;
av= ( x+y+z
) / 3;
Cout
<< " The average = " << av ;
}
Q1:B-
Define the following terms:
Coputer,
programming
Sol:
Computer: is a device capable of performing computations
and making logical decisions at speeds millions and even billions of times
faster than human beings.
Programming: is the process of writing instructions for a
computer in a certain order to solve a problem.
Q2:A
What is
the output of the following program?
#include<iostream.h>
void main( )
{
int a, b;
float first , second, third;
a=13; b=3;
first= a
+ b;
second=a/b;
third=a%b;
cout
<< "The Results are as follows"<<endl;
cout
<< "The value of first is:"<<first<<endl;
cout
<< "The value of second is:"<<second<<endl;
cout
<< "The value of third
is:"<<third<<endl;
}
Sol:
The
output of program is:
The
Results are as follows
The
value of first is:16.0
The
value of second is:4.33
The
value of third is:1.0
Q2:B-
C++
has become quite popular programming language why? (9 Marks)
Sol:
C++ has become quite popular due to the
following reasons:
1. It supports all features of both structured
programming and OOP.
2. C++ focuses on function and class templates
for handling data types.
Q3:A
Rewrite
the following program to be in a legal form, and show the output of it. (16
Marks)
#include<iostream.h>
void main( );
{
it a,c;
a=10;
b=21;
c=a+b
cout<<endl;
cout >> “the result is:"
cot<<endl;
cout<<c;
}
Sol:
The Legal form
#include<iostream.h>
void main( )
{
int a,b,c;
a=10;
b=21;
c=a+b;
cout<<endl;
cout << “the result is:";
cout<<endl;
cout>>c;
The output
the result is:
31
Q3:B
What is an algorithm mean, list the properties of an Algorithm.
Sol:
In programming, algorithm are the set of well-defined instruction in
sequence to solve a program. An algorithm should always have a clear stopping
point.
Properties are:
1.
Inputs and outputs should be defined precisely.
2.
Each steps in algorithm should be clear and unambiguous.
3.
Algorithm should be most effective among many different ways to solve a
problem.
4. An algorithm shouldn t have
computer code. Instead, the algorithm should be written in such a way that, it
can be used in similar programming languages.
Q4/A Write an algorithm for
Printing numbers from 1 to 20:
Sol:
Step 1: Start
Step 2: Initialize X as 0
Step 3: Increment X by 1
Step 4: Print X
Step 5: If X is less than 20
then go back to step 3
Step 6: Stop
Q4:B:
What is the output of the following C++ program
#include<iostream.h>
void main( )
{
int
x, y, z, r ; Output
x=
7 / 2;
cout
<< "x=" << x <<endl;
y=17/(-3);
cout
<< "y="<< y <<endl;
z=-17/3;
cout
<< "z="<< z <<endl;
r=-17/(-3);
cout
<< "r="<< r <<endl;
}
Sol:
x=3
y=-5
z=-5
r=5
Q5:A
Write
the following equation as a C++ expression: (10 Marks)
Sol:
f =
sqrt ((sin(x) – pow(x,5)) / (log(x) + x/4));
Q5:B
Convert the following
algorithm into flowchart
1- Start
2- Read x
3- If x is greater than or equal zero then go
to 5
4- If x is less than zero then go to 7
5- Print "positive"
6- Go to 8
7- Print "negative"
8- End
Sol: