Output
Enter principal, rate and time: 10000 8.5 3 Simple interest = 2550 Total amount = 12550
#include <iostream>
using namespace std;
int main()
{
float p, r, t, si;
cout << "Enter principal, rate and time: ";
cin >> p >> r >> t;All 26 practicals of MSBTE K-scheme 313304 Object Oriented Programming using C++ (Sem 3), solved. Every question has 3 different programs with the real output, a line-by-line explanation and viva questions. Choose the answer you like for each practical and print your own practical file.
💡 Explain buttons are for your understanding — explanations are never printed.
Practical 1Compulsory
Aim: Read values with cin, evaluate an expression and print the result with cout.
QWrite a program to evaluate any expression using cin and cout.
Showing answer A of 3 · tap A, B or C to see the others
Output
Enter principal, rate and time: 10000 8.5 3 Simple interest = 2550 Total amount = 12550
#include <iostream>
using namespace std;
int main()
{
float p, r, t, si;
cout << "Enter principal, rate and time: ";
cin >> p >> r >> t;Output
Enter radius: 7 Area = 153.938 Perimeter = 43.9823
#include <iostream>
using namespace std;
int main()
{
const float PI = 3.14159f;
float r;
cout << "Enter radius: ";Output
Enter temperature in Celsius: 37.5 37.5 C = 99.5 F
#include <iostream>
using namespace std;
int main()
{
double c, f;
cout << "Enter temperature in Celsius: ";
cin >> c;Practical 2Compulsory
Aim: Use the :: operator, allocate and free memory with new and delete, and format output with manipulators.
Q1Program 1: use the scope resolution operator (::).
Showing answer A of 3 · tap A, B or C to see the others
Output
Local m = 20 Global m = 10 Global m after change = 15
#include <iostream>
using namespace std;
int m = 10; // global
int main()
{
int m = 20; // localOutput
Inner block x = 5 Global x = 100 main() x = 50
#include <iostream>
using namespace std;
int x = 100;
int main()
{
int x = 50;Output
Area of rectangle = 60
#include <iostream>
using namespace std;
class Rectangle
{
int l, b;
public:
void set(int x, int y);Q2Program 2: use the memory management operators new and delete.
Showing answer A of 3 · tap A, B or C to see the others
Output
Enter an integer: 42 Value at p = 42 Value at q = 4.75 Memory released.
#include <iostream>
using namespace std;
int main()
{
int *p = new int;
float *q = new float(4.75f);
Output
How many subjects? 4 Marks of subject 1: 72 Marks of subject 2: 65 Marks of subject 3: 88 Marks of subject 4: 91 Total = 316, Average = 79
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "How many subjects? ";
cin >> n;Output
Roll 7 : Riya
#include <iostream>
using namespace std;
class Student
{
public:
int roll;
string name;Q3Program 3: use manipulators to format the output.
Showing answer A of 3 · tap A, B or C to see the others
Output
Subject Marks Maths 78 Physics 64 C++ 91
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << setw(12) << left << "Subject" << setw(8) << right << "Marks" << endl;
cout << setw(12) << left << "Maths" << setw(8) << right << 78 << endl;Output
Default : 3.14286 2 decimal places: 3.14 4 decimal places: 3.1429
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double pi = 22.0 / 7;
cout << "Default : " << pi << endl;Output
*******255 000042 Decimal 255 Hex ff Octal 377
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n = 255;
cout << setfill('*') << setw(10) << n << endl;Practical 3
Aim: See how C++ converts types automatically and convert them yourself with a cast.
QWrite programs to show implicit and explicit type conversion.
Showing answer A of 3 · tap A, B or C to see the others
Output
i + f = 9.5 c + 1 = 66 i / 2 = 3
#include <iostream>
using namespace std;
int main()
{
int i = 7;
float f = 2.5f;
char c = 'A';Output
Without cast : 87 C-style cast : 87.4 static_cast : 87.4
#include <iostream>
using namespace std;
int main()
{
int total = 437, subjects = 5;
float wrong = total / subjects;Output
Price : 149.99 Rupees only : 149 Code 98 as char: b
#include <iostream>
using namespace std;
int main()
{
float price = 149.99f;
int rupees = int(price);
int code = 98;Practical 4
Aim: Create a class with data members and member functions written inside the class, and use it through objects.
QWrite a program using a class whose member functions are defined inside the class.
Showing answer A of 3 · tap A, B or C to see the others
Output
Enter roll, name and percentage: 21 Aman 78.5 Roll: 21 Name: Aman Percentage: 78.5
#include <iostream>
using namespace std;
class Student
{
int roll;
string name;
float per;Output
A/c 1001 balance: Rs 6300 Insufficient balance! A/c 1001 balance: Rs 6300
#include <iostream>
using namespace std;
class Account
{
long accNo;
double balance;
public:Output
Volume of box 1 = 24 Volume of box 2 = 125
#include <iostream>
using namespace std;
class Box
{
int l, b, h;
public:
void set(int x, int y, int z) { l = x; b = y; h = z; }Practical 5Compulsory
Aim: Declare member functions inside the class and write their body outside it using the scope resolution operator.
QWrite a program in which member functions are defined outside the class.
Showing answer A of 3 · tap A, B or C to see the others
Output
Enter id, name and basic salary: 101 Neha 20000 Id: 101 Name: Neha Net salary: 34000
#include <iostream>
using namespace std;
class Employee
{
int id;
string name;
float basic;Output
2 hours 45 minutes 4 hours 25 minutes
#include <iostream>
using namespace std;
class Time
{
int h, m;
public:
void set(int hh, int mm);Output
Enter three numbers: 34 91 56 Largest = 91
#include <iostream>
using namespace std;
class Numbers
{
int a, b, c;
public:
void read();Practical 6Compulsory
Aim: Write small functions as inline so the compiler can put their code at the place of the call.
QWrite a program to demonstrate inline functions.
Showing answer A of 3 · tap A, B or C to see the others
Output
Enter a number: 6 Square = 36 Cube = 216
#include <iostream>
using namespace std;
inline int square(int x) { return x * x; }
inline int cube(int x) { return x * x * x; }
int main()
{Output
Area of circle = 78.5
#include <iostream>
using namespace std;
class Circle
{
float r;
public:
void set(float x);Output
Enter two numbers: 18 42 Maximum = 42 Minimum = 18
#include <iostream>
using namespace std;
inline int maxOf(int a, int b) { return (a > b) ? a : b; }
inline int minOf(int a, int b) { return (a < b) ? a : b; }
int main()
{Practical 7Compulsory
Aim: Let a non-member function read the private data of one or two classes by declaring it as a friend.
Q1Program 1: friend function shared by two different classes.
Showing answer A of 3 · tap A, B or C to see the others
Output
Largest = 72 (class B)
#include <iostream>
using namespace std;
class B; // forward declaration
class A
{
int x;Output
First = 10 Second = 20 After swap: First = 20 Second = 10
#include <iostream>
using namespace std;
class Second;
class First
{
int v;Output
Total salary = Rs 87000
#include <iostream>
using namespace std;
class Clerk;
class Manager
{
float salary;Q2Program 2: external (non-member) function as a friend of one class.
Showing answer A of 3 · tap A, B or C to see the others
Output
Enter marks of 3 subjects: 67 82 74 Average = 74.3333
#include <iostream>
using namespace std;
class Marks
{
int m1, m2, m3;
public:
void read()Output
Distance = 5
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
float x, y;
public:Output
Title: Let Us C++ Price: Rs 425
#include <iostream>
using namespace std;
class Book
{
string title;
float price;
public:Practical 8Compulsory
Aim: Share one data member among all objects of a class and use a static function to read it.
QWrite a program to demonstrate a static data member and a static member function.
Showing answer A of 3 · tap A, B or C to see the others
Output
Students admitted: 1 Students admitted: 3
#include <iostream>
using namespace std;
class Student
{
int roll;
static int count;
public:Output
Roll 101 : Rahul Roll 102 : Sneha Roll 103 : Imran Next roll number will be 104
#include <iostream>
using namespace std;
class Admission
{
int roll;
string name;
static int next;Output
Balance 10000 -> interest 600 Balance 25000 -> interest 1500 Rate changed to 7.5% Balance 10000 -> interest 750 Balance 25000 -> interest 1875
#include <iostream>
using namespace std;
class Account
{
double balance;
static float rate;
public:Practical 9Compulsory
Aim: Store many objects of a class in an array and process them in a loop.
QWrite a program using an array of objects.
Showing answer A of 3 · tap A, B or C to see the others
Output
Roll, name, percentage: 1 Asha 81.5 Roll, name, percentage: 2 Vikas 76 Roll, name, percentage: 3 Pooja 88.25 Roll Name Percent 1 Asha 81.5 2 Vikas 76 3 Pooja 88.25 Topper: 3 Pooja 88.25
#include <iostream>
using namespace std;
class Student
{
int roll;
string name;
float per;Output
Anil : Rs 25000 Meena : Rs 32000 Joseph : Rs 28500 Farah : Rs 41000 Total salary bill = Rs 126500
#include <iostream>
using namespace std;
class Employee
{
string name;
float salary;
public:Output
Pen 5 x 10 = 50 Notebook 3 x 45 = 135 Bag 1 x 650 = 650 Bill total = Rs 835
#include <iostream>
using namespace std;
class Item
{
string name;
int qty;
float rate;Practical 10Compulsory
Aim: Initialise objects automatically with constructors and use more than one constructor in the same class.
Q1Program 1: default, parameterized and copy constructor.
Showing answer A of 3 · tap A, B or C to see the others
Output
Default constructor Parameterized constructor Copy constructor Roll 0, Percentage 0 Roll 12, Percentage 84.5 Roll 12, Percentage 84.5
#include <iostream>
using namespace std;
class Student
{
int roll;
float per;
public:Output
(copy constructor called) Area r1 = 1 Area r2 = 48 Area r3 = 48
#include <iostream>
using namespace std;
class Rectangle
{
int l, b;
public:
Rectangle() { l = 1; b = 1; }Output
Not set : Rs 0 Kiran : Rs 12000 Kiran (joint) : Rs 12000
#include <iostream>
using namespace std;
class Account
{
string name;
double balance;
public:Q2Program 2: more than one constructor in one class (constructor overloading).
Showing answer A of 3 · tap A, B or C to see the others
Output
0 + 0i 4.5 + 0i 3 + 7i
#include <iostream>
using namespace std;
class Complex
{
float real, imag;
public:
Complex() { real = 0; imag = 0; }Output
P=10000 R=7% T=2 -> SI = 1400 P=10000 R=9.5% T=2 -> SI = 1900
#include <iostream>
using namespace std;
class Interest
{
double p;
float rate;
int years;Output
1/1/2026 15/8/2026 26/1/1950
#include <iostream>
using namespace std;
class Date
{
int d, m, y;
public:
Date() { d = 1; m = 1; y = 2026; }Practical 11
Aim: Derive a new class from an existing class (single) and a class from a derived class (multilevel).
Q1Program 1: single level inheritance.
Showing answer A of 3 · tap A, B or C to see the others
Output
Roll: 5 Name: Tanvi Total: 163 Percentage: 81.5
#include <iostream>
using namespace std;
class Student
{
protected:
int roll;
string name;Output
Swift: 4 wheels, runs on Petrol
#include <iostream>
using namespace std;
class Vehicle
{
protected:
int wheels;
string fuel;Output
Area = 42.25 Perimeter = 26
#include <iostream>
using namespace std;
class Shape
{
protected:
float side;
public:Q2Program 2: multilevel inheritance.
Showing answer A of 3 · tap A, B or C to see the others
Output
Roll 17: 71.5 + 64 = 135.5
#include <iostream>
using namespace std;
class Student
{
protected:
int roll;
public:Output
Sunita earns Rs 63000 (salary 55000 + bonus 8000)
#include <iostream>
using namespace std;
class Person
{
protected:
string name;
public:Output
Constructor of A Constructor of B Constructor of C
#include <iostream>
using namespace std;
class A
{
public:
A() { cout << "Constructor of A" << endl; }
};Practical 12Compulsory
Aim: Derive one class from two or more base classes.
QWrite a program to implement multiple inheritance.
Showing answer A of 3 · tap A, B or C to see the others
Output
Marks: 76 + 81, Sports: 9 Grand total = 166
#include <iostream>
using namespace std;
class Marks
{
protected:
int m1, m2;
public:Output
Photo taken with 50 MP camera Calling 98XXXXXX10... Smartphone: 50 MP, SIM 98XXXXXX10
#include <iostream>
using namespace std;
class Camera
{
protected:
int megapixel;
public:Output
Constructor A Constructor B Constructor C show() of A show() of B
#include <iostream>
using namespace std;
class A
{
public:
A() { cout << "Constructor A" << endl; }
void show() { cout << "show() of A" << endl; }Practical 13
Aim: Derive several classes from one common base class.
QWrite a program to implement hierarchical inheritance.
Showing answer A of 3 · tap A, B or C to see the others
Output
Rectangle area = 40 Triangle area = 20 Circle area = 28.26
#include <iostream>
using namespace std;
class Shape
{
protected:
float a, b;
public:Output
Ravi (permanent) gets Rs 51000 Lata (contract) gets Rs 19800
#include <iostream>
using namespace std;
class Employee
{
protected:
string name;
public:Output
Savings 2001: interest = 2000 Current 3001: monthly charge = 500
#include <iostream>
using namespace std;
class Account
{
protected:
long accNo;
double balance;Practical 14Compulsory
Aim: Avoid two copies of a grandparent class in hybrid (diamond) inheritance by making it a virtual base class.
QWrite a program to demonstrate a virtual base class.
Showing answer A of 3 · tap A, B or C to see the others
Output
Roll 11: marks 152 + sports 8 = 160
#include <iostream>
using namespace std;
class Student
{
protected:
int roll;
public:Output
Size of A : 40 bytes D1 (normal, two copies of A) : 80 bytes D2 (virtual, one copy of A) : 56 bytes
#include <iostream>
using namespace std;
class A { public: int data[10]; };
class B1 : public A {};
class C1 : public A {};
class D1 : public B1, public C1 {};Output
Person constructor Employee constructor Customer constructor StaffCustomer constructor Prakash is a staff member who also shops here.
#include <iostream>
using namespace std;
class Person
{
protected:
string name;
public:Practical 15
Aim: Pass values from a derived class constructor to the base class constructor and see the order of calls.
QWrite a program to use constructors in a derived class.
Showing answer A of 3 · tap A, B or C to see the others
Output
Person constructor Student constructor Om, age 19, roll 23
#include <iostream>
using namespace std;
class Person
{
protected:
string name;
int age;Output
Base constructor Derived constructor Object in use Derived destructor Base destructor Block ended
#include <iostream>
using namespace std;
class Base
{
public:
Base() { cout << "Base constructor" << endl; }
~Base() { cout << "Base destructor" << endl; }Output
Marks(86) Bonus(5) Result: total = 91
#include <iostream>
using namespace std;
class Marks
{
protected:
int m;
public:Practical 16Compulsory
Aim: Reach object members through a pointer and use the this pointer inside member functions.
Q1Program 1: pointer to an object.
Showing answer A of 3 · tap A, B or C to see the others
Output
Code 501, Price Rs 249.5 Code 501, Price Rs 249.5
#include <iostream>
using namespace std;
class Item
{
int code;
float price;
public:Output
Roll 1 : 72.5% Roll 2 : 81% Roll 3 : 66.25%
#include <iostream>
using namespace std;
class Student
{
int roll;
float per;
public:Output
Enter radius: 4 Area = 50.24
#include <iostream>
using namespace std;
class Circle
{
float r;
public:
Circle(float x) { r = x; }Q2Program 2: use the this pointer.
Showing answer A of 3 · tap A, B or C to see the others
Output
Roll 14 : Kavya
#include <iostream>
using namespace std;
class Student
{
int roll;
string name;
public:Output
Elder person: Nisha (41 years)
#include <iostream>
using namespace std;
class Person
{
string name;
int age;
public:Output
Called by object 1 Called by object 2 d1.isSame(&d1) : 1 d1.isSame(&d2) : 0
#include <iostream>
using namespace std;
class Demo
{
int id;
public:
Demo(int i) { id = i; }Practical 17Compulsory
Aim: Use a base class pointer to point to derived class objects and see which function gets called.
QWrite a program to use a pointer to a derived class in single and multilevel inheritance.
Showing answer A of 3 · tap A, B or C to see the others
Output
Base show(): b = 10 Derived show(): b = 10, d = 20
#include <iostream>
using namespace std;
class Base
{
public:
int b;
void show() { cout << "Base show(): b = " << b << endl; }Output
I am A I am A I am A I am B
#include <iostream>
using namespace std;
class A
{
public:
void who() { cout << "I am A" << endl; }
};Output
MH26 AB 1234 - 150 cc
#include <iostream>
using namespace std;
class Vehicle
{
public:
string number;
};Practical 18
Aim: Write several functions with the same name that differ in the number or type of arguments.
QWrite a program to demonstrate function overloading.
Showing answer A of 3 · tap A, B or C to see the others
Output
Circle (r = 5) : 78.5 Rectangle (8 x 6) : 48 Triangle (b=10, h=7) : 35
#include <iostream>
using namespace std;
float area(float r) { return 3.14f * r * r; }
int area(int l, int b) { return l * b; }
double area(double b, double h) { return 0.5 * b * h; }
int main()Output
add(4, 9) = 13 add(2.5, 3.75) = 6.25 add(10, 20, 30) = 60
#include <iostream>
using namespace std;
int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }
int add(int a, int b, int c) { return a + b + c; }
int main()Output
Integer : 25 Decimal : 99.95 Text : Ananda Pattern : ########
#include <iostream>
using namespace std;
class Printer
{
public:
void print(int n) { cout << "Integer : " << n << endl; }
void print(double d) { cout << "Decimal : " << d << endl; }Practical 19Compulsory
Aim: Give a meaning to operators like -, ++ and -- for objects of your own class.
Q1Program 1: overload a unary operator using a member function.
Showing answer A of 3 · tap A, B or C to see the others
Output
Before: (4, -7) After : (-4, 7)
#include <iostream>
using namespace std;
class Point
{
int x, y;
public:
Point(int a, int b) { x = a; y = b; }Output
Count = 3
#include <iostream>
using namespace std;
class Counter
{
int count;
public:
Counter() { count = 0; }Output
Pen drive in stock: 3 Pen drive in stock: 0 Pen drive in stock: 0
#include <iostream>
using namespace std;
class Stock
{
string item;
int qty;
public:Q2Program 2: overload a unary operator using a friend function.
Showing answer A of 3 · tap A, B or C to see the others
Output
a = 15, b = -20 a = -15, b = 20
#include <iostream>
using namespace std;
class Number
{
int a, b;
public:
Number(int x, int y) { a = x; b = y; }Output
Marks = 33 After grace: Marks = 38
#include <iostream>
using namespace std;
class Marks
{
int m;
public:
Marks(int x) { m = x; }Output
Cart 1 is empty Cart 2 is not empty
#include <iostream>
using namespace std;
class Cart
{
int items;
public:
Cart(int n) { items = n; }Practical 20
Aim: Use operators like +, -, * and == between two objects of your class.
Q1Program 1: overload a binary operator using a member function.
Showing answer A of 3 · tap A, B or C to see the others
Output
c1 = 3 + 4i c2 = 2.5 - 1.5i c3 = 5.5 + 2.5i
#include <iostream>
using namespace std;
class Complex
{
float re, im;
public:
Complex(float r = 0, float i = 0) { re = r; im = i; }Output
Total = 9 ft 4 in
#include <iostream>
using namespace std;
class Distance
{
int feet, inch;
public:
Distance(int f = 0, int i = 0) { feet = f; inch = i; }Output
birthday == today ? Yes birthday == exam ? No
#include <iostream>
using namespace std;
class Date
{
int d, m, y;
public:
Date(int a, int b, int c) { d = a; m = b; y = c; }Q2Program 2: overload a binary operator using a friend function.
Showing answer A of 3 · tap A, B or C to see the others
Output
c1 - c2 = 5 - 3i
#include <iostream>
using namespace std;
class Complex
{
float re, im;
public:
Complex(float r = 0, float i = 0) { re = r; im = i; }Output
4 tickets: Rs 1400 3 tickets: Rs 1050
#include <iostream>
using namespace std;
class Money
{
int rupees;
public:
Money(int r) { rupees = r; }Output
m1 + m2 = 6 8 10 12
#include <iostream>
using namespace std;
class Matrix
{
int a[2][2];
public:
Matrix(int p, int q, int r, int s) { a[0][0] = p; a[0][1] = q; a[1][0] = r; a[1][1] = s; }Practical 21Compulsory
Aim: Make a base class pointer call the function of the actual derived object (run-time polymorphism).
QWrite a program to demonstrate a virtual function.
Showing answer A of 3 · tap A, B or C to see the others
Output
show() of Derived display() of Base (not virtual)
#include <iostream>
using namespace std;
class Base
{
public:
virtual void show() { cout << "show() of Base" << endl; }
void display() { cout << "display() of Base (not virtual)" << endl; }Output
Drawing a shape Drawing a circle Drawing a square
#include <iostream>
using namespace std;
class Shape
{
public:
virtual void draw() { cout << "Drawing a shape" << endl; }
};Output
Deepa : Rs 42000 Arjun : Rs 15000
#include <iostream>
using namespace std;
class Employee
{
protected:
string name;
public:Practical 22
Aim: Create an abstract base class with a pure virtual function that every derived class must define.
QWrite a program to demonstrate a pure virtual function.
Showing answer A of 3 · tap A, B or C to see the others
Output
Rectangle area = 60 Circle area = 153.86
#include <iostream>
using namespace std;
class Shape
{
public:
virtual float area() = 0;
};Output
Paid Rs 1200 by UPI Paid Rs 1224 by card (2% charge)
#include <iostream>
using namespace std;
class Payment
{
public:
virtual void pay(float amt) = 0;
};Output
Dog says: Woof Cow says: Moo
#include <iostream>
using namespace std;
class Animal
{
protected:
string name;
public:Practical 23Compulsory
Aim: Open files in two ways — by passing the name to the stream constructor and by calling open() — then write and read data.
Q1Program 1: open a file using the constructor of the stream class.
Showing answer A of 3 · tap A, B or C to see the others
Output
Data written to student.txt Reading the file: Roll: 12 Name: Sakshi Branch: CO
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream fout("student.txt");
fout << "Roll: 12" << endl;Output
Numbers in file: 1 2 3 4 5 6 7 8 9 10 Sum = 55
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream out("numbers.txt");
for (int i = 1; i <= 10; i++)Output
missing_file.txt could not be opened notes.txt contains: C++ file handling practical
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream f1("missing_file.txt");
if (!f1)Q2Program 2: open a file using the open() function.
Showing answer A of 3 · tap A, B or C to see the others
Output
1. Nanded 2. Pune 3. Nagpur
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream fout;
fout.open("cities.txt");Output
Line 1: created Line 2: added later
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream f;
f.open("log.txt");Output
Maths : 78 C++ : 91 Total = 169
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file;
file.open("marks.txt", ios::out);Practical 24Compulsory
Aim: Read data from a source file and write it into a target file.
QWrite a program to copy the content of one file into another.
Showing answer A of 3 · tap A, B or C to see the others
Output
3 lines copied to copy.txt Ananda Technologies C++ practical 24 File copy demo
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream make("source.txt");
make << "Ananda Technologies" << endl << "C++ practical 24" << endl << "File copy demo" << endl;Output
25 characters copied from a.txt to b.txt
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream make("a.txt");
make << "Hello C++\nFiles are easy.";Output
ITEM PRICE PEN 10 NOTEBOOK 45 BAG 650
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
using namespace std;
int main()
{Practical 25
Aim: Write records one after another into a file and read them back in the same order.
QWrite a program for sequential input and output on a file.
Showing answer A of 3 · tap A, B or C to see the others
Output
How many employees? 3 Id, name, salary: 1 Ganesh 28000 Id, name, salary: 2 Rekha 31500 Id, name, salary: 3 Salim 26000 Records in file: 1 Ganesh 28000 2 Rekha 31500 3 Salim 26000
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int n;
cout << "How many employees? ";Output
Characters written: 10 Read back: ABCDEFGHIJ
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream out("abc.txt");
for (char c = 'A'; c <= 'J'; c++)Output
Lines: 3, Words: 12, Characters: 89
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream out("para.txt");
out << "C++ supports object oriented programming." << endl;Practical 26
Aim: Store whole objects in a binary file with write() and read them back with read().
QWrite a program to perform input and output on a binary file.
Showing answer A of 3 · tap A, B or C to see the others
Output
Roll Name Percent 1 Anil 74.5 2 Bhakti 88 3 Chetan 69.25
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
class Student
{
int roll;Output
Record 2 -> code 102, price 99 File size = 24 bytes (3 records)
#include <iostream>
#include <fstream>
using namespace std;
struct Item
{
int code;
float price;Output
Accounts after deposit in A/c 3: A/c 1 : Rs 5000 A/c 2 : Rs 12000 A/c 3 : Rs 2300
#include <iostream>
#include <fstream>
using namespace std;
struct Account
{
int no;
double balance;Tick the answers you want in your file
Accept the marks of 5 students in 5 subjects, calculate the percentage and grade of each student, find the topper and write all records to a file.
WHAT YOU SUBMIT
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int SUBJECTS = 5;
const int STUDENTS = 5;
class Student
{===== STUDENT GRADING SYSTEM ===== Student 1 name: Asha Marks of 5 subjects: 78 82 69 91 87 Student 2 name: Vikas Marks of 5 subjects: 61 55 72 66 58 Student 3 name: Sameer Marks of 5 subjects: 45 38 52 60 49 Student 4 name: Pooja
MSBTE asks for a GitHub repository with at least 3 commits and a README. You do this yourself, free:
Tip: a free account here shows the full code of every micro project and practical.
Free practicals, micro projects and question papers for your semesters — and when your final year comes, ready projects with report, setup and viva help.
Send it to your class WhatsApp group — practical file done in minutes for everyone, free.