Professional Documents
Culture Documents
C++ LAB
BCA 2nd Year, 3rd Semester
SECTION – B
Submitted To
Mr. Piyush Kumar Gupta
(Assistant Professor)
Submitted By:
Mohd Shifan Saud
2020-301-086
(Signature)
JAMIA HAMDARD
Department of Computer Science & Engineering
School of Engineering Sciences & Technology
New Delhi-110062
INDEX
Sl. Signatur
C++ Programs
No. e
Subject Marks
1.
Mathematics 90
Computer 77
Chemistry 69
Write a program which accept principle, rate and time from user
3.
and print the simple interest.
For example, when user enters a number, 575, the results would
be like this...
500: 1
100: 0
50: 1
20: 1
10: 0
5: 1
1: 0
Plus Rs. 0.40 per call for any call beyond 200 calls.
admno integer
sname 20 character
total float
Write the definition for a class called complex that has floating
point data members for storing real and imaginary parts. The
class has the following member functions:
class Sample
private:
int x;
double y;
public :
Sample(); //Constructor 1
Sample(int); //Constructor 2
};
Write a menu driven program for bank user who has two a/c
saving and current where he can check the balance, update the
27.
balance and withdraw the amount, and calculate the interest
using inheritance concept.
31. Create a class named 'Rectangle' with two data members- length
and breadth and a function to calculate the area which is
'length*breadth'. The class has three constructors which are :
Now, create objects of the 'Rectangle' class having none, one and
two parameters and print their areas.
Write a program that takes your full name as input and displays
the abbreviations of the first and middle names except the last
35.
name which is displayed as it is. For example, if your name is
Robert Brett Roser, then the output should be R.B.Roser.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int sub1,sub2,sub3;
cout<<"Enter Mathematics marks = ";
cin>>sub1;
cout<<"Enter Computer marks = ";
cin>>sub2;
cout<<"Enter Chemistry marks = ";
cin>>sub3;
cout<<"\nSubject\t\t\tMarks\n";
cout<<"\nMathematics\t\t"<<sub1;
cout<<"\nComputer\t\t"<<sub2;
cout<<"\nChemistry\t\t"<<sub3;
getch();
}
Q2
#include<iostream>
using namespace std;
int main()
{
float centigrade;
float fahrenheit;
cout<<"Enter temp. in Fahrenheit: ";
cin>>fahrenheit;
cout<<endl;
centigrade = (fahrenheit - 32) * 5/9;
Output:
Enter temp. in Fahrenheit: 93
Temp. in Celsius: 33.8889
Q3.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int principle,rate,time,intrest;
cout<<"Enter Principle = ";
cin>>principle;
cout<<"Enter Rate = ";
cin>>rate;
cout<<"Enter Time = ";
cin>>time;
intrest=(principle*time*rate)/100;
cout<<"The intrest rate is "<<intrest;
getch();
}
OUTPUT
Enter Principle = 1300
Enter Rate = 7
Enter Time = 54
int temp;
temp = x;
x = y;
y = temp;
int main()
int a, b;
cin>>a;
cin>>b;
swap(a, b);
}
Q6.
OUTPUT
Q7 #include <iostream>
string message;
cout<<message<<"\n";
int main() {
CheckNumber(5.5);
CheckNumber(-10.8);
return 0;
OUTPUT
Positive number
Negative number
Q8 A sequence of characters can be represented using an object of a class in C++. The class which
provides a definition to do so is called a String class. String header <string> needs to be included in the
program to use the String class. Let us understand how to declare and assign a value to a string.
C++ allows you to specify more than one definition for a function name or an operator in the same scope, which is
called function overloading and operator overloading respectively.
#include<iostream>
#include<stdio.h>
#include<string.h>
class String
char str[20];
public:
void getdata()
gets(str);
if(!strcmp(str,s.str))
return 1;
return 0;
};
int main()
String s1,s2;
s1.getdata();
if(s1==s2)
else
return 0;
OUTPUT
Process returned 0
Q9.
OUTPUT
Q 10
OUTPUT
Q 11.
OUTPUT
Q 12.
OUTPUT
Q 13
OUTPUT
Q14
OUTPUT
Q15
OUTPUT
Q16
OUTPUT
Q 17
OUTPUT
Q18
OUTPUT
Q 19
OUTPUT
Q 20
Q 21
OUTPUT
Q22
Q 23
Q 24
OUTPUT
Q25
Q26
i.
Sample :: Sample()
{
x = 0;
y = 0;
}
ii.
Sample :: Sample(int a)
{
x = a;
y = 0;
}
iii.
Sample :: Sample(int a, int b)
{
x = a;
y = b;
}
Sample :: Sample(int a, double b)
{
x = a;
y = b;
}
Q27
Q28
OUTPUT
Q29
OUTPUT
Q30
Output
Q 31
OUTPUT
Q32
OUTPUT
Q33
OUTPUT