CS-I Practicals Answer Key 11th

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

STD 11th: Computer Science (Part I):

C++ programming using C++ compiler and VB Script


Experiment No. 01:- STUDY OF STRUCTURE OF C++ PROGRAM.

Aim: Write a program in C++ to display a message as “Welcome to C++ programming. C++ is
better than C.”

Note: - Write the below answer on proper printout of Practical file sheet.

// Basic program based on the structure of C++

#include<iostream.h> //calling header files

#include<conio.h> //optional based on compiler

void main(){ // main function to start execution by


compiler

cout<<” Welcome to C++ programming. C++ is better than C.”;

// cout function to print the statement

getch() // optional based on compiler

Output:

Welcome to C++ programming. C++ is better than C.


Experiment No. 02:- Study of C++ Program using Operators.

Aim: Write a program in C++ to perform operation on two integers.”

Note: - Write the below answer on proper printout of Practical file sheet.

// Online C++ compiler to run C++ program online


#include <iostream>
using namespace std;
int main() {
int num1,num2,result;
char oprt;
double flt;
cout<<"Enter first integer number"<<endl;
cin>>num1;
cout<<"Enter second integer number"<<endl;
cin>>num2;
cout<<"Enter operator"<<endl;
cin>>oprt;
if(oprt=='+'){
result = num1+num2;
cout<<"Result: "<<num1<<'+'<<num2<<" = "<<result;
}else if(oprt=='-'){
result = num1-num2;
cout<<"Result: "<<num1<<'-'<<num2<<" = "<<result;
}else if(oprt=='*'){
result = num1*num2;
cout<<"Result: "<<num1<<'*'<<num2<<" = "<<result;
}else if(oprt=='/'){
if(num2==0){
cout<<"Denominator can\’t be zero";
}else{
flt = num1/num2;
cout<<"Result: "<<num1<<'/'<<num2<<" = "<<flt;
}
}else{
cout<<"invalid operator";
}
return 0;
}

Output:
Enter first integer number
10
Enter second integer number
5
Enter operator
+
Result: 10+5 = 15
Experiment No. 03:- Study of C++ Program using Control Structure.
Aim: Write a program in C++ to Display Odd numbers between 1 to 100 using loop”
Note: - Write the below answer on proper printout of Practical file sheet.
#include <iostream>

using namespace std;

int main() {

int num,i,cnt;

i=0;

num=100;

cnt=0;

for(i;i<=num;i++){

if(i%2!=0){

cnt=cnt+1;

cout<<i<<"\t";

if(cnt==10){

cnt=0;

cout<<endl;

return 0;

}
Output:
1 3 5 7 9 11 13 15 17 19
21 23 25 27 29 31 33 35 37 39
41 43 45 47 49 51 53 55 57 59
61 63 65 67 69 71 73 75 77 79
81 83 85 87 89 91 93 95 97 99
Experiment No. 04:- Study of C++ Program using functions.
Aim: Write a program in C++ to interchange two integer numbers using call by reference.”
Note: - Write the below answer on proper printout of Practical file sheet.
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
void swap(int *,int *);
int main() {
int num1,num2;
cout<<"Enter first number"<<endl;
cin>>num1;
cout<<"Enter second number"<<endl;
cin>>num2;
cout<<"Numbers before swapping: Num1= " <<num1<<" and Num2=
"<<num2<<endl;
swap(&num1,&num2);
cout<<"Numbers After Swapping, Num1="<<num1<<" and Num2=
"<<num2;
return 0;
}
void swap(int *x,int *y){
int temp;
temp=*x;
*x=*y;
*y=temp;
}
Output:

Enter first number

10

Enter second number

15

Numbers before swapping: Num1= 10 and Num2= 15

Numbers After Swapping, Num1=15 and Num2= 10


Experiment No. 05:- Study of C++ Program using functions.
Aim: Write a program in C++ to interchange two integer numbers using call by value.”
Note: - Write the below answer on proper printout of Practical file sheet.

// Online C++ compiler to run C++ program online

#include <iostream>
using namespace std;
void swap(int,int);
int main() {
int num1,num2;
cout<<"Enter first number"<<endl;
cin>>num1;
cout<<"Enter second number"<<endl;
cin>>num2;
cout<<"Numbers before swapping: Num1= " <<num1<<" and Num2=
"<<num2<<endl;
swap(num1,num2);
return 0;
}
void swap(int x,int y){
int temp;
temp=x;
x=y;
y=temp;
cout<<"Numbers After Swapping, Num1="<<x<<" and Num2= "<<y;
}

Output:

Enter first number

Enter second number

Numbers before swapping: Num1= 5 and Num2= 7

Numbers After Swapping, Num1=7 and Num2= 5


Experiment No. 06:- Study of C++ Program using Arrays.
Aim: Write a program in C++ to Display the elements of an array.”
Note: - Write the below answer on proper printout of Practical file sheet.

// Online C++ compiler to run C++ program online


#include <iostream>
using namespace std;
int main() {
int size,i;
cout<<"Enter size of array"<<endl;
cin>>size;
int arry[size];
for(i=0;i<size;i++){
cout<<"Enter element "<<i+1<<" : ";
cin>>arry[i];
}
cout<<"Elements in array you entered are: ";
cout<<"[ ";
for(i=0;i<size;i++){
cout<<arry[i]<<ends;
}
cout<<"]";

return 0;
}
Output:

Enter size of array : 5

Enter element 1 : 2

Enter element 2 : 4

Enter element 3 : 6

Enter element 4 : 8

Enter element 5 : 10

Elements in array you entered are: [ 2 4 6 8 10 ]


Experiment No. 07:- Study of C++ program.
Aim: Write a program in C++ to display numbers from 0 to 15 in 4x4 matrix form.”
Note: - Write the below answer on proper printout of Practical file sheet.

// Online C++ compiler to run C++ program online

#include <iostream>

using namespace std;

int main() {

int cnt=1;

for(int i=0;i<=15;i++){

cout<<i<<"\t";

if(cnt%4==0)

cout<<endl;

cnt++;

return 0;

Output:

0 1 2 3

4 5 6 7

8 9 10 11

12 13 14 15
Experiment No. 08:- Study of C++ programming.
Aim: Write a program in C++ to draw a right angle triangle with ‘*’.
Note: - Write the below answer on proper printout of Practical file sheet.

// Online C++ compiler to run C++ program online


#include <iostream>
using namespace std;

int main() {
char ch='*';
int size;
cout<<"Enter the length of side ";
cin>>size;
for(int i=1;i<=size;i++){
for(int j=0;j<i;j++){
cout<<ch<<ends;
}
cout<<endl;
}

return 0;
}
Output:
Enter the length of side 4
*
* *
* * *
* * * *
Experiment No. 09:- Study of Visual Basic Application.
Aim: Write a program in VB to calculate sum of numbers within a range using loop.”
Note: - Write the below answer on proper printout of Practical file sheet.
Private Sub Command1_Click()
Dim sum As Double
Dim k As Integer
Sum=0
i=Text1.Text
j=Text2.Text
k=i
while k<= j
sum=sum+k
k=k+1
wend
Text3.Text=sum
End Sub
Experiment No. 10:- Study of Visual Basic Addition/Substraction Application.
Aim: Write a program in VB to design application window.”
Note: - Write the below answer on proper printout of Practical file sheet.

For answer refer R.D. Supekar (Revised) page no. 253

You might also like