practical programs of c++ vaibhav
TRANSCRIPT
-
8/7/2019 Practical Programs of C++ Vaibhav
1/21
Practical Programs of C++
List of all programs in Sem 4
1. Reverse of a Number
2. Factorial of a Number
3. Switch program for :
a. Sin
b. Cos
c. Factorial
d. Power
e. Square root of a Number.
4. Palindrome of a Number.
5. Write A Program (WAP) using class student which has
access specified as public and the name of function
getmarks() and totalmarks() of 2 subjects. Thisprogram will accept marks of two subjects (using
getmarks()) and adds them then displays total addition
of marks(using totalmarks()).
6.
7. Program to obtain result of a BSc.IT student as per the ATKT pattern if
the student is having KT print number of KT and Subject Name in which
he failed.If more than 2KTs fail & If no kt pass
Assessed By - Miss Maunika Kamadi
-
8/7/2019 Practical Programs of C++ Vaibhav
2/21
1. Reverse of a Number
Code:
#include
#include //For clrscr() & getch()//
void main()
{
long num, digit, rev=0;
clrscr();
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
3/21
OUTPUT:
************************************************** *
* Program for Reverse of a Number *
* *
*************************************************
Enter the Number
154
Reverse = 451
Assessed By - Miss Maunika Kamadi
-
8/7/2019 Practical Programs of C++ Vaibhav
4/21
2. Factorial of a Number
Code:
#include
#include
void main()
{
clrscr();
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
5/21
OUTPUT:
*************************************************
* ** Program for Factorial of a Number *
* *
*************************************************
Enter the Number to find its Factorial
8
Factorial => 40320
Assessed By - Miss Maunika Kamadi
-
8/7/2019 Practical Programs of C++ Vaibhav
6/21
3. Switch case to perform certain operations on a Number
Code:
#include
#include
#include //For Math functions like Sin,Cos & Pow
void main()
{
int num,sw;
float ans;
clrscr();
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
7/21
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
8/21
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
9/21
-
8/7/2019 Practical Programs of C++ Vaibhav
10/21
OUTPUT for option 2:
Program to find Power of a number
Enter the base value2
Enter the power
4
16
OUTPUT for option 3:
Enter the number to find its Squareroot
5
Squareroot of num=2.236068
OUTPUT for option 4:
Enter the number to finds its Sin
5
Sin of number=-0.958924
OUTPUT for option 5:
Enter the number to find its Cos6
Cos of number=0.96017
OUTPUT for default option:
U ENTERED WRONG OPTION !!!!!!!!!!!
Assessed By - Miss Maunika Kamadi
-
8/7/2019 Practical Programs of C++ Vaibhav
11/21
4. Palindrome of a Number
Code:
#include
#include
void main()
{
long number,num, digit, rev=0; // initialize three integer variables
clrscr();
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
12/21
else
{
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
13/21
5. Studying how to use class and functions in a program
Code:
#include
#include
class student //student is the name of class
{
int marks1, marks2;
public: // access specifier as public
void getmarks();
/*Declaring a Function & void specifies return type of function getmarks.*/
void totalmarks();
/*Declaring a function & void specifies return type of function totalmarks.*/
};
void student:: getmarks() /*void - return type & student - class name & :: -
scope resolution operator for getmarks*/
{
coutmarks1 >> marks2;
}
void student:: totalmarks()
{
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
14/21
getch();
}
OUTPUT:
Enter the marks of Two Subjects
98
96
The marks for two subjects are
98 96
Total of Marks =>194
Assessed By - Miss Maunika Kamadi
-
8/7/2019 Practical Programs of C++ Vaibhav
15/21
6.
#include
#include
class student
{
char name[20];
int rollno;
int marks[5];
int total;
float per;
public:
void getdata();
void getmarks();
void showdata();
void showmarks();
};
void student :: getdata(){
coutname;
coutrollno;
}
void student :: getmarks()
{
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
16/21
void student :: showdata()
{
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
17/21
7. Program to obtain result of a BSc.IT student as per the ATKT pattern if the
student is having KT print number of KT and Subject Name in which he failed.
If more than 2KTs fail & If no kt pass
Code:#include
#include
class student //This class contains basic info like Name and Roll no.
{
int rollno; // As it is private cannot be used outside this class
public:
char name[30]; //Name declared in array
void getdata();
void showdata();
};
void student :: getdata() //This function is used to Obtain Name and Roll no
{
coutname;
coutrollno;
}
void student :: showdata() //This function Displays Name and Roll no
{
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
18/21
{
public:
int marks[5]; //Marksvoid getmarks();
};
void marks :: getmarks()
{
coutmarks[i];
}
}
class bonus_marks: public marks
{
public:
void bonusgrace();
void total();
void showmarks();
};
void bonus_marks :: bonusgrace()
{
for (int i=0; i
-
8/7/2019 Practical Programs of C++ Vaibhav
19/21
void bonus_marks :: total()
{
int total=0;
for(int i=0 ; i
-
8/7/2019 Practical Programs of C++ Vaibhav
20/21
++count;
}
}
if (count>0){
cout
-
8/7/2019 Practical Programs of C++ Vaibhav
21/21
cout