Proc++ Divya
Proc++ Divya
CERTIFICATE
Programming using C++ for the term ending in Month October and year
2024 - 2025.
Date:15 – 08 - 2024
Name: Name:
CHIRAG MEHTA
Signature: Signature:
VANITA VISHRAM WOMEN’S UNIVERSITY
Managed By Vanita Vishram, Surat
School of Science and Technology
Department of Computer Science
Program: BCA
Problem Sheet
YEAR 2024 – 2025
Sub: - CAM206-2C: Programming using C++
#include <conio.h>
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
else {
else {
} else {
void main() {
clrscr();
int year;
if (isLeapYear(year)) {
} else {
cout << year << " is not a leap year." << endl;
getch();
private:
char customerName[50];
int customerID;
int unitsConsumed;
float billAmount;
public:
// Function to input customer details
void inputDetails() {
cout << "Enter Customer Name: ";
cin >> customerName;
cout << "Enter Customer ID: ";
cin >> customerID;
cout << "Enter Units Consumed: ";
cin >> unitsConsumed;
}
// Function to calculate the bill
void calculateBill() {
if (unitsConsumed <= 100) {
1
clrscr();
ElectricityBill bill;
// Input customer details
bill.inputDetails();
// Calculate the bill
bill.calculateBill();
// Display the bill
bill.displayBill();
1
getch();
return 0;
}
3. Write a program to find square root of float and integer using inline function.
#include<iostream.h>
#include<conio.h>
#include<math.h>
// Inline function to calculate square root
inline float calculateSqrt(float num) {
return sqrt(num);
}
int main() {
clrscr();
int intNum;
float floatNum;
// Input integer number
cout << "Enter an integer number: ";
cin >> intNum;
// Input floating-point number
cout << "Enter a floating-point number: ";
cin >> floatNum;
return 0;
}
5. Write a program for static data member using student class with data members rollNo,
Name and Marks. Count the total number of objects created for same.
#include<iostream.h>
#include<conio.h>
#include<string.h> // Include this header for strcpy function
class Student {
private:
int rollNo;
char Name[50];
float Marks;
public:
static int count; // Static data member to count number of objects
// Constructor to initialize student details
Student(int r, char n[], float m) {
rollNo = r;
strcpy(Name, n); // Copy the string n into Name
Marks = m;
count++; // Increment the object count each time a new object is created
}
// Function to display student details
void display() {
cout << "Roll No: " << rollNo << endl;
cout << "Name: " << Name << endl;
cout << "Marks: " << Marks << endl;
}
1
int main() {
clrscr();
// Create student objects
Student s1(1, "John", 85.5);
Student s2(2, "Alice", 90.0);
Student s3(3, "Bob", 78.5);
// Display details of each student
cout << "Details of Student 1:" << endl;
s1.display();
cout << "\nDetails of Student 2:" << endl;
s2.display();
cout << "\nDetails of Student 3:" << endl;
s3.display();
// Display total number of objects created
Student::showCount();
getch();
return 0;
}
1
6. Write a program for static member function using item class with data members
itemcode, price and quantity and count total number of item purchased.
#include<iostream.h>
#include<conio.h>
class Item {
public:
int itemcode;
float price;
int quantity;
static int count; // Static data member to count total number of items purchased
// Constructor to initialize item details
Item(int code, float pr, int qty) {
itemcode = code;
price = pr;
quantity = qty;
cout << "\nTotal number of items purchased: " << count << endl;
}
}; // Initialize the static data member
int Item::count = 0;
int main() {
clrscr(); // Create item objects
Item item1(101, 15.50, 2);
Item item2(102, 25.75, 3);
Item item3(103, 40.00, 5);
// Display details of each item
cout << "Details of Item 1:" << endl;
item1.display();
cout << "\nDetails of Item 2:" << endl;
item2.display();
#include<conio.h>
class Marksheet {
char name[50];
int rollNumber;
public:
void inputData() {
cout<<" ";
cout<<" ";
}
void displayData() {
};
void main() {
clrscr();
int n;
1
cin >> n;
students[i].inputData();
cout<<" ";
cout<<"\n\t\t\t\tEnglish\tMaths\tScience\n";
students[i].displayData();
}
getch();
8. Create a class student which have id, name, address details. Use new and delete to create
dynamic object creation.
#include <iostream.h>
#include <conio.h>
class Student {
public:
1
int id;
char name[50];
char address[100];
id = studentId;
strcpy(name, studentName);
strcpy(address, studentAddress);
void display() {
// Destructor
~Student() {
};
int main() {
studentPtr->display();
delete studentPtr;
getch(); // Wait for user input before closing the console window
return 0;
}
1
9. Write a program of class circle and calculate area of circle using constructor overloading
and destructor.
#include <iostream.h>
#include <conio.h>
class Circle {
public:
Circle() {
radius = 0.0;
} // Parameterized constructor
Circle(float r) {
radius = r;
}
float calculateArea() {
// Destructor
~Circle() {
};
void main() {
clrscr();
Circle c1;
cout << "Area of circle with radius " << c1.radius << " is: " << c1.calculateArea() << endl;
Circle c2(5.0);
1
cout << "Area of circle with radius " << c2.radius << " is: " << c2.calculateArea() << endl;
getch();
10. Write a program to accept 5 Employee detail which have id, name, salary members.
Display employee detail whose salary is greater than 10000.
#include <iostream.h>
#include <conio.h>
class Employee {
public:
int id;
char name[30];
void acceptDetails() {
void displayDetails() {
};
void main() {
clrscr();
Employee employees[5];
1
cout << "Enter details for Employee " << (i + 1) << ":" << endl;
employees[i].acceptDetails();
cout << "Employees with salary greater than 10000:" << endl;
employees[i].displayDetails();
}
}
getch();
11. Write a c++ program to create objects of distance class then input two distances in
feet and inches and output the sum of two distances. Make use of Constructors and
Destructors.
#include <iostream.h>
#include <conio.h>
1
class Distance {
public:
int feet;
Distance() {
feet = 0;
inches = 0;
} // Parameterized constructor
Distance(int f, int i) {
feet = f;
inches = i;
void inputDistance() {
void displayDistance() {
cout << feet << " feet " << inches << " inches" << endl;
Distance addDistance(Distance d) {
Distance temp;
}
1
return temp;
// Destructor
~Distance() {
cout << "Destructor called for Distance object with " << feet << " feet " << inches << " inches" << endl;
};
void main() {
clrscr();
d1.inputDistance();
d2.inputDistance();
Distance d3 = d1.addDistance(d2);
d3.displayDistance();
getch();
12. Write a program for class Transport with properties wheels, name, color, type for various
#include <conio.h>
#include<string.h>
class Transport {
public:
int wheels;
char name[30];
char color[20];
char type[30];
// Default constructor
Transport() {
wheels = 0;
strcpy(name, "Unknown");
strcpy(color, "Unknown");
strcpy(type, "Unknown");
wheels = w;
strcpy(name, n);
strcpy(color, "Unknown");
strcpy(type, "Unknown");
wheels = w;
strcpy(name, n);
strcpy(color, c);
strcpy(type, "Unknown");
wheels = w;
1
strcpy(name, n);
strcpy(color, c);
strcpy(type, t);
void displayDetails() {
// Destructor
~Transport() {
cout << "Destructor called for " << name << endl;
};
void main() {
clrscr();
Transport t1;
t1.displayDetails();
t2.displayDetails();
t3.displayDetails();
1
t4.displayDetails();
getch();
Inheritance:
13. Create a class mathop1 which have calresult() [which calculate square], create another class
mathop2 which have calresult() [which calculate cube], inherit both classes in calc class.
#include <iostream.h>
#include <conio.h>
class MathOp1 {
public:
void calResult(int num) {
cout << "Square of " << num << " is: " << square << endl;
1
};
class MathOp2 {
public:
cout << "Cube of " << num << " is: " << cube << endl;
};
public:
};
void main() {
clrscr();
Calc obj;
int num;
obj.calSquare(num);
obj.calCube(num);
getch();
}
1
14. Create a base class Vehicle with attributes like color, maxSpeed, and methods like
displayDetails(). Derive classes Car, Truck, and Motorcycle with additional attributes and
methods.
#include <iostream.h>
#include <conio.h>
class Vehicle {
public:
char color[20];
int maxSpeed;
strcpy(color, c);
maxSpeed = s;
void displayDetails() {
cout << "Max Speed: " << maxSpeed << " km/h" << endl;
};
public:
int numberOfDoors;
numberOfDoors = doors;
void displayDetails() {
};
public:
int loadCapacity;
loadCapacity = capacity;
void displayDetails() {
cout << "Load Capacity: " << loadCapacity << " tons" << endl;
};
public:
int hasSidecar; // Changed from bool to int for Turbo C++ compatibility
hasSidecar = sidecar;
void displayDetails() {
cout << "Has Sidecar: " << (hasSidecar ? "Yes" : "No") << endl;
};
void main() {
1
clrscr();
myCar.displayDetails();
myTruck.displayDetails();
Motorcycle myMotorcycle("Black", 180, 1); // Use 1 instead of true for Turbo C++ compatibility
myMotorcycle.displayDetails();
getch();
15. Create a base class Person with attributes like name, age, and address. Derive classes
Student, Professor, and Staff with additional attributes and methods.
#include <iostream.h>
#include <conio.h>
#include <string.h> // Include this for strcpy()
class Person {
public:
1
char name[30];
int age;
char address[50];
// Constructor to initialize Person
Person(const char* n, int a, const char* addr) {
strcpy(name, n);
age = a;
strcpy(address, addr);
}
// Method to display person details
void displayDetails() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
public:
int studentID;
char course[30];
}
// Method to display student details
void displayDetails() {
Person::displayDetails(); // Call base class method
cout << "Student ID: " << studentID << endl;
1
strcpy(department, dept);
}
// Method to display professor details
void displayDetails() {
Person::displayDetails(); // Call base class method
cout << "Employee ID: " << employeeID << endl;
cout << "Department: " << department << endl;
}
};
class Staff : public Person {
public:
int staffID;
char role[30];
}
// Method to display staff details
1
void displayDetails() {
Person::displayDetails(); // Call base class method
cout << "Staff ID: " << staffID << endl;
professor.displayDetails();
cout << endl; // Creating a Staff object
Staff staff("John", 35, "789 Pine Road", 3001, "Administrative Assistant");
cout << "Staff Details:" << endl;
staff.displayDetails();
cout << endl;
getch();
}
1
Friend Function:
16. Create a class BankAccount with private attributes account_number and balance.
Implement a friend function display_account_info that can access and print the private
attributes of the BankAccount class.
#include <iostream.h>
#include <conio.h>
class BankAccount {
public:
int account_number;
float balance;
account_number = acc_no;
balance = bal;
};
void main() {
clrscr();
display_account_info(myAccount);
getch();
Polymorphism
17. Create a class geometric which overload area() function.
When given a single value, calculate the area of a square.
For two input returns area assumes the figure is a rectangle.
When a floating-point number is passed to the function, it calculates and returns the
area of a circle.
#include <iostream.h>
#include <conio.h>
class Geometric {
public:
// Function to calculate the area of a square
};
void main() {
clrscr();
Geometric shape;
int square_side = 5;
cout << "Area of Square with side " << square_side << " is: " << shape.area(square_side) << endl;
cout << "Area of Rectangle with length " << length << " and width " << width << " is: " << shape.area(length, width)
<< endl;
cout << "Area of Circle with radius " << radius << " is: " << shape.area(radius) << endl;
getch();
#include <conio.h>
class Counter {
public:
int count;
Counter(int c = 0) {
1
count = c;
void operator++() {
++count;
void operator--() {
--count;
void display() {
};
void main() {
clrscr();
c.display();
c.display();
c.display();
getch();