Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

GOVERNMENT ENGINEERING COLLEGE BILASPUR (C.G.

)
Class Test No 1
B.E. Civil (5th Semester)
Numerical Methods and Computer Programming
Standard Solution
Question 1:
a) Define algorithm?
An algorithm is a procedure or formula for solving a problem, based on conducting a sequence of
specified actions. A computer program can be viewed as an elaborate algorithm. In mathematics and
computer science, an algorithm usually means a small procedure that solves a recurrent problem.
b) What is flow chart. Explain the meaning of the standard symbols used in flow chart with their names
and neat sketch?
A flow chart is a graphical or symbolic representation of a process. Each step in the process is
represented by a different symbol and contains a short description of the process step. The flow chart
symbols are linked together with arrows showing the process flow direction.

c) Write a program in C++ to find the area of the triangle and rectangle separately?
#include <iostream.h>
#include <conio.h>
class shape
{
protected:
double x,y;
public:
virtualvoid get_data()=0;
virtualvoid display_area()=0;
};
class triangle : public shape
{
public:
void get_data(void)
{
cout<<"\n\n=====Data Entry for Triangle=====\n\n";
cout<<"Enter base and height respectively : ";
cin>>x>>y;
}
void display_area(void)
{
cout<<"\n\n=====Area of Triangle=====\n\n";
double aot;
aot = 0.5 * x * y;
cout<<"Area of Triangle is "<<aot;
}

};
class rectangle : public shape
{
public:
void get_data(void)
{
cout<<"\n\n=====Data Entry for Rectangle=====\n\n";
cout<<"Enter length of two sides : ";
cin>>x>>y;
}
void display_area(void)
{
cout<<"\n\n=====Area of rectangle=====\n\n";
double aor;
aor = x * y;
cout<<"Area of Rectangle is "<<aor;
}
};
void main()
{
clrscr();
triangle tri;
rectangle rect;
shape *list[2];
list[0]=&tri;
list[1]=&rect;
int choice;
while(1)
{
clrscr();
cout<<"\n=====MEASURES OF DIFFERENT SHAPE=====\n";
cout<<"\nChoose your choice\n";
cout<<"1) Area of Triangle\n";
cout<<"2) Area of Rectangle\n";
cout<<"3) Exit\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1 : list[0]->get_data();
list[0]->display_area();
getch();
break;
case 2 : list[1]->get_data();
list[1]->display_area();
getch();
break;
case 3 : goto end;
default: cout<<"\n\nInvalid choice\nTry again\n";
getch();
}
}
end:
}
d) Write a program in C++ to find the sum of two matrices.
#include<iostream.h>

#include<conio.h>
void main()
{
int x[3][3],y[3][3],z[3][3],i,j;
clrscr();
cout<<"ENTER ELEMENTS OF 1st MATRIX\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>x[i][j];
}
cout<<"ENTER ELEMENTS OF 2nd MATRIX\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>y[i][j];
}
cout<<"MATRIX [X]";
for(i=0;i<3;i++)
{
cout<<"\n\n";
for(j=0;j<3;j++)
cout<<x[i][j];
}
cout<<"\nMATRIX [Y]";
for(i=0;i<3;i++)
{
cout<<"\n\n";
for(j=0;j<3;j++)
cout<<y[i][j];
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
z[i][j]=x[i][j]+y[i][j];
}
cout<<"\nMATRIX [Z]";
for(i=0;i<3;i++)
{
cout<<"\n\n";
for(j=0;j<3;j++)
cout<<z[i][j];
}
getch();
}
Question : 2

a) Define constant and variable in C++ with example.

You might also like