You are on page 1of 42

SRI KRISHNA ARTS AND SCIENCE COLLEGE

An Autonomous College Affiliated to Bharathiar University

Re-Accredited by NAAC with ‘A’ Grade

Coimbatore – 641008

DEPARTMENT OF COMMERCE IT & ECOM

NAME:

ROLLNO:

PROGRAMME CLASS

COURSE:
SRI KRISHNA ARTS AND SCIENCE COLLEGE
An Autonomous College Affiliated to Bharathiar University

Re-Accredited by NAAC with ‘A’ Grade

Coimbatore – 641008

ROLL NUMBER:

Certified bonafide record of work done by …………………………………………………..

During the academic year 2023-2024 fourth semester.

Staff In-charge Head of the Department

Submitted to the Sri Krishna Arts and Science College (Autonomous) End
Semester Examinations held on………………………………

Internal Examiner External Examiner


DECLARATION

I _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ hereby declare that this record


of observations is based on the experiments carried out and recorded by me
during the laboratory classes of “ ”
conducted by SRI KRISHNA ARTS AND SCIENCE COLLEGE, Coimbatore-
641 008.

DATE:

Signature of the student

Name of the student:


Roll number:

Counter signed by staff


INDEX

S. No. Date Name of the Program Page No. Signature

1. Create Payroll Calculation

Calculate working capital using class and


2.
objects

Calculate Contribution P/V ratio, BEP and


3.
margin of safety using Functions

Calculate Simple Interest and Compound


4.
Interest using inline functions

Calculate Depreciation using Constructor and


5.
Destructor

Calculate Sum and Product of two numbers


6.
using operator overloading

7. Prepare a cost sheet using Inheritance

Create employee information using


8.
polymorphism

9. Merge two files into a single file

Prepare the mark slip of the students in a file


10.
Ex.No:1

Date:
CREATE PAYROLL CALCULATION

AIM:
To write a C++ program to read data of N employee and create payroll calculation of
each employee.

ALGORITHM:
STEP1 - Include the required header files (iostream.h, conio.h).
STEP 2 - Create a class Employee with the following members. emp_number,
emp_name, basic, da, it, gross_salary, and net_salary as data members and member functions are
setvalues, calculateworking capital, display result.read_emp_details(), find_net_salary(), and
display_emp_details() as member functions.
STEP 3 - Implement all the member functions with their respective code.
STEP 4 - Create a main() method.
STEP 5 - Create an array of class object with a specific size and number_of_emp as
integer.
STEP 6 - Read number_of_emp.
STEP 7 - Call the read_emp_details() method through the array of class object from 0
tonumber_of_emp.
STEP 8 - Call the find_net_salary() method through the array of class object from 0
tonumber_of_emp.
STEP 9 - Call the display_emp_details() method through the array of class object from 0
tonumber_of_emp.
STEP 10 - return 0 to exit from the program execution.
PROGRAM:

#include<iostream.h>
#include<conio.h>
class Employee
{
char emp_name[30];
int emp_number;
float basic, da, it, gross_salary, net_salary;
public:
void read_emp_details(int count){
cout<<"\n\n*** Enter Employee "<<count<<" Details ***";
cout<<"\nEmployee Number: ";
cin>>emp_number;
cout<<"Employee Name: ";
cin>>emp_name;
cout<<"Basic Salary: ";
cin>>basic;
cout<<"\n---- Employee "<<count<<" Datails are saved ---- \n\n";
}
float find_net_salary(){
da = basic * 0.52;
gross_salary = basic + da;
it = gross_salary * 0.30;
net_salary = (basic + da) - it;
returnnet_salary;
}
void display_emp_details(int count){
cout<<"\n\n*** Employee "<<count<<" Details ***\n";
cout<<"\nEmployee Number : "<<emp_number;
cout<<"\nEmployee Name : "<<emp_name;
cout<<"\nNet Salary: "<<net_salary;
cout<<"\n \n";
}
};
int main(){
Employee emp[100];
int number_of_emp, count;
clrscr();
cout<<"\nPlease enter the number of Employees (Max. 100): ";
cin>>number_of_emp;
for(count=0; count<number_of_emp; count++){
emp[count].read_emp_details(count+1);
}
for(count=0; count<number_of_emp; count++){
emp[count].find_net_salary();
}
for(count=0; count<number_of_emp; count++){
emp[count].display_emp_details(count+1);
}
cout<<"\nPress any key to close!!!";
getch();
return 0;
}
OUTPUT:

RESULT:

Thus the program has been executed successfully and the output is verified.
Ex.No:2 CALCULATE WORKING CAPITAL USING
Date: CLASS AND OBJECTS

AIM:
To a C++ Program to calculate Working capital using class and objects(Member function
should be inside and outside the class).

ALGORITHM:
STEP1: Include the required header files (iostream.h, conio.h).
STEP2: Create a class with class name WorkingCapitalCalculator with the following
members currentAssets and currentLiabilities.
STEP3: Declare currentAssets and currentLiabilities under private access specifier of
type float.
STEP4: Define member function setValues with assets and liabilities as parameter values.
STEP5: Assign currentAssets as assets and currentLiabilities as liabilities.
STEP6: Define member function calculateWorkingCapital by returning the subtraction
value of currentAssets and currentLiabilities.
STEP7: Define member function displayResult where the member function
calculateWorkingCapital is called in cout statement and the return value of calculateWorking
Capital is displayed.
STEP8 : Here displayResult function member function is declared inside the class and is
defined outside the class using scope resolution operator (::).
STEP9: Define the main function
STEP10: Create an object for WorkingCapitalCalculator as company.
STEP11: Call the member function company.setvalues as 500000 and 300000.
STEP12: Call the member function company.displayresult().
STEP13: Stop the program.
PROGRAM:
#include<iostream.h>
#include<conio.h>
class WorkingCapitalCalculator {
private:
float currentAssets;
float currentLiabilities;
public:
void setValues(float assets, float liabilities)
{
currentAssets = assets;
currentLiabilities = liabilities;
}
float calculateWorkingCapital()
{
return currentAssets - currentLiabilities;
}
void displayResult();
};
void WorkingCapitalCalculator::displayResult{
cout<<”Working Capital: “<<calculateWorkingCapital()<<endl;
}
int main() {
clrscr();
WorkingCapitalCalculator company;
// Set values using the member function inside the class
company.setValues(1800, 1000);
// Display result using the member function outside the class
company.displayResult();
getch();
return 0;}
OUTPUT:

RESULT:
Thus the program has been executed successfully and the output is verified.
Ex.No:3 CALCULATE CONTRIBUTION,P/V RATIO,BEP AND
Date: MARGIN OF SAFETY USING FUNCTIONS

AIM:
To calculate Contribution, P/v ratio, BEP and Margin of Safety using Functions.

ALGORITHM:
STEP1: Start the program.
STEP2: Include the header file iostream.h and conio.h.
STEP3: Define the function calculateContribution by returning sales-variablecost.
STEP4: Define the function calculatePVRatio by returning contribution/sales*100.
STEP4: Define the function calculateBEP by returning fixedcost/contribution.
STEP5:Define the function calculateMarginOfSafety by returning totalSales -
breakEvenSales / totalSales * 100.
STEP6: Declare the main function double type variable sales, variableCost,
fixedCost,totalSales and store the input from the user in those variables.
STEP7: Call the function calculateContribution, calculatePvRatio,calculateBEP,
calculateMarginOfsafety.
STEP8: Display the values for calculateContribution, calculatePVRatio,calculateBEP,
calculateMarginOfSafety.
STEP9:Stop the program.
PROGRAM:
#include <iostream.h>
# include<conio.h>
double calculateContribution(double sales, double variableCost) {
return sales - variableCost;
}
double calculatePvRatio(double contribution, double sales) {
return contribution / sales * 100;
}
double calculateBEP(double fixedCost, double contribution) {
return fixedCost / contribution;
}
double calculateMarginOfSafety(double sales, double breakEvenSales) {
return (sales - breakEvenSales) / sales * 100;
}
int main() {
clrscr();
double sales, variableCost, fixedCost,totalSales;
cout << "Enter Selling price of a product per unit : $";
cin>> sales;
cout << "Enter Variable Cost per unit : $";
cin>>variableCost;
cout << "Enter Total Fixed Cost: $";
cin>>fixedCost;
cout<<”Enter Total sales : $“;
cin>>totalSales;
double contribution = calculateContribution(sales, variableCost);
cout << "Contribution: $" << contribution <<endl;
double pvRatio = calculatePvRatio(contribution, sales);
cout << "P/v Ratio: " <<pvRatio<< "%" <<endl;
double breakEvenPoint = calculateBEP(fixedCost, contribution);
cout << "Break-Even Point: " <<breakEvenPoint<< " units" <<endl;
double marginOfSafety = calculateMarginOfSafety(totalSales,fixedCost/pvRatio*100);
/* we are sending breakEvenPoint in dollars as parameters and so we are using formula :
BreakEvenPoint in Dollars = fixedCost/pvRatio*100 */
cout << "Margin of Safety: " <<marginOfSafety<< "%" <<endl;
getch();
return 0;
}
OUTPUT:

RESULT:
Thus the program has been executed successfully and the output is verified.
Ex.No:4 CALCULATE SIMPLE INTEREST AND COMPOUND
Date:
INTEREST USING INLINE FUNCTIONS

AIM:
To calculate simple interest and compound interest using inline function.

ALGORITHM:
STEP1: Start the program.
STEP2: Include the header files iostream.h,math.h and conio.h.
STEP3: Create an inline function to calculate si with principal, rate and time as parameter
values.
STEP4: Create an inline function to calculate ci with principal, rate and time as parameter
values.
STEP5: Define main function and get the values of principal, rate and time as user input.
STEP6: Call si() to calculate si and store it in simpleinterest variable.
STEP7: Call ci() to calculate ci and store it in compoundinterest variable.
STEP8: Stop the program.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<math.h>
// Inline function to calculate simple interest
inline float si(float principal, float rate, int time) {
return (principal * time * rate) / 100;
}
// Inline function to calculate compound interest
inline float ci(float principal, float rate, int time) {
return principal * pow( (1 + rate / 100), time) - principal;
}
int main() {
clrscr();
float principal, rate;
int time;
// Input principal amount, rate of interest, and time
cout << "Enter principal amount: ";
cin>> principal;
cout << "Enter rate of interest: ";
cin>> rate;
cout << "Enter time (in years): ";
cin>> time;
// Calculate and display simple interest
float simpleInterest = si(principal, rate, time);
cout << "Simple Interest: " <<simpleInterest<<endl;
// Calculate and display compound interest
float compoundInterest = ci(principal, rate, time);
cout << "Compound Interest: " <<compoundInterest<<endl;
getch();
return 0; }
OUTPUT:

RESULT:
Thus the program has been executed successfully and the output is verified.
Ex.No:5 CALCULATE DEPRECIATION USING CONSTRUCTOR
Date: AND DESTRUCTOR

AIM:
To create a program in C++ to Calculate Depreciation – by using constructor and
Destructor.

ALGORITHM:
STEP1: Start the program.
STEP2: Include the header files iostream.h,conio.h
STEP3: Create a class DepreciationCalculator with variables initialCost,
depreciationRate, time.
STEP4: Create a constructor to initialize the values to the variables and display text
“Depreciation calculator created.”
STEP5: Create a destructor to display text “Depreciation calculator destroyed.”
STEP6: Define the member function calculateDepreciation() and calculate the
depreciation as initialCost * (depreciationRate / 100) * years;
STEP7: Create a main function with cost, rate and time.
STEP8: Create an object calculator for Depreciationcalculator.
STEP9: Calculate the member function and store the returned value in depreciation.
STEP10: Display the depreciation value.
STEP11: Stop the program.
PROGRAM:

#include<iostream.h>
#include<conio.h>
class DepreciationCalculator {
private:
float initialCost;
float depreciationRate;
int years;
public:
DepreciationCalculator(float cost, float rate, int time){
// Setting or initializing value to the the data members in the constructor
initialCost = cost;
depreciationRate = rate;
years = time;
cout << "Depreciation Calculator Created" <<endl;
}
~DepreciationCalculator() {
cout << "Depreciation Calculator Destroyed" <<endl;
}
float calculateDepreciation() {
float depreciation = initialCost * (depreciationRate / 100) * years;
return depreciation;
}
};
int main() {
clrscr();
float cost, rate;
int time;
cout << "Enter initial cost: ";
cin>> cost;
cout << "Enter depreciation rate (in percentage): ";
cin>> rate;
cout << "Enter time (in years): ";
cin>> time;
DepreciationCalculatorcalculator(cost, rate, time);
float depreciation = calculator.calculateDepreciation();
cout << "Depreciation after " << time << " years: " << depreciation <<endl;
getch();
return 0;
}
OUTPUT:

RESULT:
Thus the program has been executed and the output is verified successfully.
Ex.No:6 CALCULATE SUM AND PRODUCT OF TWO NUMBERS
Date: USING OPERATOR OVERLOADING

AIM:
To write a C++ program to calculate sum and product of two numbers using operator
overloading.

ALGORITHM:
STEP1: Define a class named `load` with private integer members `x` and `y`.
STEP2: Inside the `load` class, create a member function `getdata()` and define the
function to prompt the user to input integer values for `x` and `y`.
STEP3: Inside the `load` class, create another member function `display()` and define the
function to display the values of `x` and `y`.
STEP4: Inside the `load` class, define a member function `operator+` and in that
overloading function, declare another object of the same class as an argument.
STEP5: Inside the function, create a temporary object of load class and set the `x` and `y`
values of the temporary object as the sum of member variables x and y in int1 and int2objects
which will be created in main function.
STEP6: Also, in the end of ‘operator+’ overloading function, call the display function of
temporary object.
STEP7: Do similar definition as same as ‘operator+’ for ‘operator*’ member function.
Inside the definition for ‘operator*’ overloading function, replace ‘+’ with ‘*’ .
STEP8: In the main function, create int1 and int2 objects and call getdata member
function of corresponding int1 and int2 objects to prompt the user to get input values.
STEP9: Call the overloaded function of + and * to calculate sum and product of 2 values.
STEP10: Conclude the main function with return 0;.
PROGRAM:

#include<iostream.h>
#include<conio.h>
class load
{
int x;
int y;
public:
void getdata()
{
cout<<"\n enter int value1:";
cin>>x;
cout<<"\n enter int value2:”;
cin>>y;
}
void display()
{
cout<<"\n x="<<x;
cout<<"\n y="<<y;
}
void operator+(load i) //addition Operator gets overloaded
{
load temp;
temp.x=x+i.x;
temp.y=y+i.y;
temp.display();
}
void operator*(load i) // multiplication operator gets overloaded
{
load temp;
temp.x=x*i.x;
temp.y=y*i.y;
temp.display();
}
};
int main()
{
clrscr();
load int1,int2;
cout<<"\n values for object1";
int1.getdata();
cout<<"\n values for object2";
int2.getdata();
int1+int2;
int1*int2;
getch();
return 0;
}
OUTPUT:

RESULT:
Thus the program has been executed successfully and the output is verified.
Ex.No:7
Date:
PREPARE A COST SHEET USING INHERITANCE

AIM:
To write a C++ program to prepare a cost sheet using Inheritance.

ALGORITHM:
STEP1: Start the program.
STEP2: Include necessary header files (`iostream.h` and `conio.h`).
STEP3: Define a class `cost` with private and protected member variables for
various cost related components and calculations.
STEP4: Under public access specifier, define member function getdata() for getting input
values for net sales, direct wages, direct material, rent, electricity, stationary, telephone bills,
travelling, and advertising and store it in corresponding member variables within the `cost` class.
STEP5: Calculate prime cost, factory cost, administration cost, selling and distribution
cost, cost of production, and profit and store it in corresponding member variables.
STEP6: Define a class `sheet` that publicly inherits from `cost`.
STEP7:Inside the derived class ‘sheet’, create a putdata() function and display the cost
sheet including net sales, prime cost, factory cost, administration cost, cost of production, selling
and distribution cost, and profit.
STEP8: In the `main` function, create an instance of the `sheet` class and call `getdata()`
to input data. Call `calculate()` to perform calculations. Call `putdata()` to display the cost sheet.
STEP9: Conclude the main function with return 0.
PROGRAM:

#include<iostream.h>
#include<conio.h>
class cost
{
private:
float dm,dw,elec,rent,stat,tb,travel,ad;
protected:
float profit,pc,fc,ac,sdc,netsales,cop;
public:
void getdata(){
cout<<"\n Enter the net sales:";
cin>>netsales;
cout<<"\n Enter the value for direct wages:";
cin>>dw;
cout<<"\n Enter the value for direct material:";
cin>>dm;
cout<<"\n Enter the value for rent:";
cin>>rent;
cout<<"\n Enter the value for electricity:";
cin>>elec;
cout<<"\n Enter the value for stationary:";
cin>>stat;
cout<<"\n Enter the value for telephone bills:";
cin>>tb;
cout<<"\n Enter the value for travelling:";
cin>>travel;
cout<<"\n Enter the value for advertising:";
cin>>ad;
}
void calculate(){
pc=dm+dw;
fc=rent+elec;
ac=stat+tb;
sdc=travel+ad;
cop=pc+fc+ac;
profit=netsales-(cop+sdc);
}
};
class sheet:public cost
{
public:
void putdata()
{
cout<<"\n\t\t COST SHEET";
cout<<"\n\n Net Sales:"<<netsales;
cout<<"\n\n Prime cost:"<<pc;
cout<<"\n\n Factory cost:"<<fc;
cout<<"\n\n Administration cost:"<<ac;
cout<<"\n ";
cout<<"\n\n Cost of production:"<<cop;
cout<<"\n\n Selling and distribution cost:"<<sdc;
cout<<"\n\n Profit:"<<profit;
cout<<"\n\n ";
}
};

int main()
{
clrscr();
sheet s;
s.getdata();
s.calculate();
s.putdata();
getch();
return 0;
}
OUTPUT:

RESULT:
Thus the program has been executed and the output is verified successfully.
Ex.No:8 CREATE EMPLOYEE INFORMATION USING
Date: POLYMORPHISM

AIM:
To write a C++ Program for employee information using Polymorphism.

ALGORITHM:
STEP1: Start the program.
STEP2: Include the header files iostream and conio.h.
STEP3: Create a main class personal with member name and age.
STEP4: Create a virtual member function getdata() and display() to get and display name
and age member variables.
STEP5: Create a subclass official by inheriting personal main class.
STEP6: Add members empno, grade and basicpay.
STEP7: Override the function getdata and display to get and display empno, grade, bp.
STEP8: In the main function create a normal object, pointer object for personal class.
STEP9: Create an object for official class. Use a pointer object to store the address of
objects of both parent and child classes to call both the versions of getdata() and display()
STEP10: Display the output.
STEP11: Stop the program.
PROGRAM:

#include<iostream.h>
#include<conio.h>
class personal
{
char name[20];
int age;
public:
virtual void getdata ()
{
cout<<” Enter the employee details”;
cout<<” \nName:”;
cin>>name;
cout<<” Age:”;
cin>>age;
}
virtual void display ()
{
cout<<” \n employee details using virtual function”;
cout<<” \n name:” <<name;
cout<<” \n age:” <<age;
}
};
class official: public personal
{
char empno [6], grade;
float bp;
void getdata ()
{
cout<<” \n enter the employee no:”;
cin>>empno;
cout<<” \n enter the grade:”;
cin>>grade;
cout<<” \n enter the basic pay:”;
cin>>bp;
}
void display ()
{
cout<<” \n employee no:” <<empno;
cout<<” \n grade:” <<grade;
cout<<” \n basic pay:” <<bp;
}
};
int main ()
{
clrscr ();
official o;
personal p, *p1;
p1= &p;
p1->getdata ();
p1=&o;
p1->getdata ();
p1=&p;
p1->display ();
p1=&o;
p1->display ();
getch ();
return 0;
}
OUTPUT:

RESULT:
Thus the program has been executed and the output is verified successfully.
Ex.No:9
Date:
MERGE TWO FILES INTO A SINGLE FILE

AIM:
To Write a program to merge 2 files into a single file.

ALGORITHM:
STEP 1: Create three files skasc.txt,ecom.txt,campus.txt and insert the content in the file1
and file2.
STEP2: Include the necessary header files.
STEP 3: Create an object ifiles1, ifiles2 from ifstream class.
STEP 4: Create another object ifilet from ofstream class.
STEP 5: Create variables fname1, fname2, fname3,content1,content2.
STEP6: Store the name of the files in fname1,fname2,fname3 variables.
STEP7: Use open() function to open the file and read the contents of file1 and file2 using
extraction operator (>>) and store the content of the file in content1,content2 variables.
STEP8: Write the contents of both the file fname1, fname2 to fname3 using insertion
operator (<<).
STEP9: Close the files using close() function.
STEP10: Stop the program.
PROGRAM:

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
int main()
{
clrscr();
ifstream ifiles1, ifiles2;
ofstream ifilet;
char fname1[20], fname2[20], fname3[20],content1[20],content2[20];
cout<<"enter first file name (with extension like file1.txt):";
cin>>fname1;
cout<<"enter second file name (with extension like file2.txt):";
cin>>fname2;
cout<<"enter name of file name (with extension like filet.txt) which will store the contents of the
two files (fname1 and fname2):";
cin>>fname3;
ifiles1.open(fname1);
ifiles2.open(fname2);
ifilet.open(fname3);
//If the file is not opened, it returns false and the below if statement gets executed
if (!ifiles1 || !ifiles2)
{
cout<<"Error in opening the file";
}
else{
while (ifiles1.eof()==0)
{
ifiles1>>content1; //Read content from file 1
ifilet<<content1; // Write the content to file 3
}
while (ifiles2.eof()==0)
{
ifiles2>>content2; //Read content from file 2
ifilet<<content2; // Write the content to file 3
}
cout<<"The two files were merged into " <<fname3<< " File Successfully...!!";
}
ifiles1.close();
ifiles2.close();
ifilet.close();
getch();
return 0;
}
OUTPUT:
skasc.txt :

ecom.txt :

campus.txt :

RESULT:
Thus the program has been executed and the output is verified successfully.
Ex.No:10 PREPARE THE MARK SLIP OF THE STUDENTS IN A
Date: FILE

AIM:
To write a C++ to create a student file and prepare the mark slip.

ALGORITHM:
STEP1: Include the necessary header files.
STEP2: Declare main function.
STEP3: Declare variables name, rollno, mark1, mark2, mark3, total, average.
STEP4: Create an object out from ofstream.
STEP5: Get the values for name, rollno, mark1, mark2, mark3 from the user as input and
store it in corresponding variables.
STEP6: Calculate the total and average.
STEP7: Display the content of the mark slip in the file by using insertion operator (<<).
STEP8: Close the file by using close() function.
STEP9: Stop the program.
PROGRAM:

#include <iostream.h>
#include<conio.h>
#include<fstream.h>

int main()
{
clrscr();
char rollno[15],name[20];
int m1,m2,m3,tot,avg;
ofstream out;
out. open (“stud1.txt”);//This statement will automatically create and open the file in write mode
cout<<”\n enter the student name: \t”;
cin>>name;
cout<<”\n enter the roll no: \t”;
cin>>rollno;
cout<<”\n enter 3 marks: \t”;
cin>>m1>>m2>>m3;
out<<”\n student markslip preparation”;
out<<”\n name \t” <<name;
out<<”\n roll no\t” <<rollno;
out<<”\n mark 1 \t” <<m1;
out<<”\n mark 2 \t” <<m2;
out<<”\n mark 3 \t” <<m3;
tot=m1+m2+m3;
avg =(tot/3);
out<<”\n total =” <<tot;
out<<\n average=” <<avg;
out.close();
getch();
return 0;}
OUTPUT:
Output console screen :

stud.txt :

RESULT:
Thus the program has been executed successfully and the output is verified.

You might also like