c++ content
c++ content
#include <iostream.h>
#include <stdlib.h>
class student {
private:
char name[30];
int rollNo;
float total;
float subject[5];
int i;
public:
void getDetails(void);
void putDetails(void);
};
void student::getDetails(void)
{
cout<< "Enter Name: ";
cin>> name;
cout<< "Enter Roll Number: ";
cin>>rollNo;
total=0;
for (i=0;i<5;i++){
cout<<"\nEnter Marks of Subject"<<i+1<<" : ";
cin>>subject[i];
total += subject[i];
}
void student::putDetails(void)
{
pupil.getDetails();
pupil.putDetails();
getch();
Output :
Program :
#include <iostream.h>
#include <stdlib.h>
void main(){
displayNum(7);
displayNum(5);
displayNum(312);
getch();
}
Output :
class Employee {
private:
char name[10];
int empId;
double salary[3];
public:
void setInput();
void display();
};
void Employee :: setInput(){
cout << "Enter Employee Name: ";
cin >> name;
cout << "Enter Employee ID: ";
cin >> empId;
for (int i = 0; i < 3; i++) {
cout << "Enter salary for year " << i + 1 << " : ";
cin >> salary[i];
} }
void Employee :: display() {
cout << "\nEmployee Details\n";
cout << "Name: " << name << endl;
cout << "Employee ID: " << empId << endl;
cout << "Salary:\n";
for (int i = 0; i < 3; i++) {
cout << "Year " << i + 1 << ": " << salary[i] << endl;
}
}
void main() {
Employee e;
e.setInput();
e.display();
getch(); }
Output :
int rollNo;
int marks;
public:
void setInput(int r, int m) {
rollNo = r;
marks = m;
}
void display() {
cout << "Roll Number: " << rollNo << endl;
cout << "Marks: " << marks << endl;
}
};
void main() {
Student students[3];
getch();
}
Output :
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
class Student {
public:
Student() { total += 1; }
};
int Student::total = 0;
void main()
{ Student s1;
Student s2;
Student s3;
getch(); }
Output :
public:
Product(int i, int r) {
this->id = i;
this->price = r;
}
void display() {
cout << "Product ID : " << this->id << endl;
cout << "Price : " << this->price << endl;
}
};
void main() {
Product P(101,969);
P.display();
getch();
}
Output :
Output :
Devesh Chopkar 10 | P a g e
Programming in C++ BCA II
getch();
}
Output :
Devesh Chopkar 11 | P a g e
Programming in C++ BCA II
Output :
Devesh Chopkar 12 | P a g e
Programming in C++ BCA II
Output :
Devesh Chopkar 13 | P a g e
Programming in C++ BCA II
Devesh Chopkar 14 | P a g e
Programming in C++ BCA II
void main() {
int num;
cout << "Enter a number: ";
cin >> num;
getch();
}
Output :
Devesh Chopkar 15 | P a g e
Programming in C++ BCA II
void main() {
Calculator calc;
getch();
}
Output :
Devesh Chopkar 16 | P a g e
Programming in C++ BCA II
15. Write a program for friend function to add data object of two different classes.
Program :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
class ClassA {
private:
int dataA;
public:
ClassA(int value) {
dataA = value;
}
friend int addData(ClassA, ClassB);
};
class ClassB {
private:
int dataB;
public:
ClassB(int value) {
dataB = value;
}
friend int addData(ClassA, ClassB);
};
Output :
Devesh Chopkar 17 | P a g e
Programming in C++ BCA II
public:
Student(char n[10], int a) {
name[10] =n[10];
age = a;
}
void display() {
cout << "Name: " << name[10] << endl;
cout << "Age: " << age << endl;
}
};
int main() {
s1.display();
s2.display();
return 0;
}
Output :
Devesh Chopkar 18 | P a g e
Programming in C++ BCA II
class Student {
private:
string name;
int age;
public:
Student(string n, int a) {
name = n;
age = a;
}
Student(const Student& s) {
name = s.name;
age = s.age;
}
void display() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
}
};
int main() {
Student s1("Devesh", 20);
Student s2(s1);
cout << "Student 1:" << endl;
s1.display();
cout << "\nStudent 2 (Copy of Student 1):" << endl;
s2.display();
return 0;
}
Output :
Devesh Chopkar 19 | P a g e
Programming in C++ BCA II
Output :
Devesh Chopkar 20 | P a g e
Programming in C++ BCA II
Output :
Devesh Chopkar 21 | P a g e
Programming in C++ BCA II
Devesh Chopkar 22 | P a g e
Programming in C++ BCA II
Devesh Chopkar 23 | P a g e
Programming in C++ BCA II
Output :
Devesh Chopkar 24 | P a g e
Programming in C++ BCA II
Devesh Chopkar 25 | P a g e
Programming in C++ BCA II
Program :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
class Shape {
public:
virtual void draw() = 0;
virtual void area() = 0;
};
public:
Circle(int radius) {
this->radius = radius;
}
void draw() {
cout << "Drawing circle..." << endl;
}
void area() {
cout << "Area of circle: " << 3.14 * radius * radius << endl;
}
};
public:
Rectangle(int length, int width) {
this->length = length;
this->width = width;
}
void draw() {
cout << "Drawing rectangle..." << endl;
}
void area() {
cout << "Area of rectangle: " << length * width << endl;
}
Devesh Chopkar 26 | P a g e
Programming in C++ BCA II
};
void main() {
Circle circle(10);
circle.draw();
circle.area();
getch();
}
Output :
Devesh Chopkar 27 | P a g e
Programming in C++ BCA II
25. Write a program using inline function to find minimum of two numbers. The inline function should
take two arguments and should return the minimum value.
Program :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
void main() {
int num1, num2;
cout << "Minimum number: " << min(num1, num2) << endl;
getch();
}
Output :
Devesh Chopkar 28 | P a g e
Programming in C++ BCA II
26. Write swapping program to demonstrate call by value, call by address and call by reference in a
single program.
Program :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
void main() {
int a = 5;
int b = 10;
cout << "Original values: a = " << a << ", b = " << b << endl;
swapByValue(a, b);
cout << "After call by value: a = " << a << ", b = " << b << endl;
swapByAddress(&a, &b);
cout << "After call by address: a = " << a << ", b = " << b << endl;
a = 5;
b = 10;
swapByReference(a, b);
cout << "After call by reference: a = " << a << ", b = " << b << endl;
getch();
}
Devesh Chopkar 29 | P a g e
Programming in C++ BCA II
Output :
Devesh Chopkar 30 | P a g e
Programming in C++ BCA II
27. Write program to find biggest number among three numbers using pointer and function.
Program :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
void main() {
int num1, num2, num3;
getch();
}
Output :
Devesh Chopkar 31 | P a g e
Programming in C++ BCA II
Program :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
bubbleSort(arr, n);
getch();
}
Output :
Devesh Chopkar 32 | P a g e
Programming in C++ BCA II
Program :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
int binarySearch(int arr[], int n, int target) {
int low = 0;
int high = n - 1;
Output :
Devesh Chopkar 33 | P a g e
Programming in C++ BCA II
30. Write a class having name Calculate that uses static overloaded function to calculate area of circle,
area of rectangle and area of triangle.
Program :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
class Calculate {
public:
Output :
Devesh Chopkar 34 | P a g e