lab manual c++
lab manual c++
Class: FYBCA
Subject: CA-113 Lab on Programming in C++
Lab Manual
//Practical 1 : Program using various arithmetic operators
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,sum,sub,mul,div,rem;
clrscr();
cout<<"\nEnter any two numbers=";
cin>>a>>b;
sum=a+b;
sub=a-b;
mul=a*b;
div=a/b;
rem=a%b;
cout<<"\nAddition="<<sum;
cout<<"\nSubstraction="<<sub;
cout<<"\nMultiplication="<<mul;
cout<<"\nDivision="<<div;
cout<<"\nReminder="<<rem;
getch();
}
e2.id=102;
e2.name=”Namrata”;
e2.salary=126000;
cout<<"employee 1 id : “<<e1.id<<endl;
cout<<"employee 1 name : “<<e1.name<<endl;
cout<<"employee 1 salary : “<<e1.salary<<endl;
cout<<"employee 2 id : “<<e2.id<<endl;
cout<<"employee 2 name : “<<e2.name<<endl;
cout<<"employee 2 salary : “<<e2.salary<<endl; return 0;
}
e1.id=101;
cout<<"employee 1 id :"<<e1.id<<endl;
e1.name=”harshal”;
cout<<"employee 1 name :"<<e1.name<<endl;
e2.id=102;
cout<<"employee 2 id :"<<e2.id<<endl;
e2.name=”Namrata”;
cout<<"employee 2 name :"<<e2.name<<endl;
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
// Define the number of students
const int NUM_STUDENTS = 10;
// Define arrays to hold the marks for 3 subjects and other necessary information
long roll_no[NUM_STUDENTS]={2022001, 2022002, 2022003, 2022004, 2022005,2022006,
2022007, 2022008, 2022009, 2022010};
int marks_sub1[NUM_STUDENTS]={40,50,65,78,98,45,63,25,72,63};
int marks_sub2[NUM_STUDENTS]={87,56,97,45,32,65,45,87,23,69};
int marks_sub3[NUM_STUDENTS]={74,62,64,75,85,56,77,64,68,78};
int total_marks[NUM_STUDENTS];
getch();
}
#include<iostream.h>
#include<conio.h>
// Function to calculate average age
double calculateAverageAge(int ages[], int classStrength = 50)
{
int totalAge = 0;
// Calculate the total age by summing up all the ages
for(int i=0;i<classStrength;i++)
{
totalAge += ages[i];
}
// Calculate and return the average age
return (double)totalAge / classStrength;
}
void main()
{
clrscr();
// Sample array of student ages (class strength 50 by default)
int studentAges[50] = {16, 17, 18, 19, 17, 16, 18, 19, 17, 16,
18, 17, 16, 19, 18, 17, 16, 18, 19, 17,
16, 18, 17, 19, 18, 16, 17, 16, 18, 19,
17, 16, 18, 19, 17, 16, 18, 19, 16, 17,
18, 17, 16, 19, 18, 16, 17, 18, 19, 17};
// Call the function to calculate the average age
double averageAge = calculateAverageAge(studentAges);
// Display the average age
cout<< "The average age of the class is: " << averageAge << endl;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int N;
// Input the number N
cout<<"Enter the number N: ";
cin>>N;
// Display the series of squares up to N
for(int i=1;i<=N;i++)
{
cout<< i * i << " "; // Print the square of the number
}
getch();
}
*****