C++ Lab Programs
C++ Lab Programs
#include <iostream>
int main()
else
return 0;
}
2. Develop a C++ program to sort the elements in ascending and descending order
#include<iostream.h>
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
cout<<a[i]<<" ";
int main()
ascDecFunc(arr, len);
return 0;
}
3. Develop a c++ program using classes to display student name , roll number ,
marks obtained in two subjects and total score of student .
#include<iostream>
#include<string>
class Student
private:
string name;
int rollNumber;
float marksSubject1;
float marksSubject2;
public:
void inputDetails()
cin>> name;
}
// Function to calculate and display total score
void displayInfo()
};
int main()
Student student;
student.inputDetails();
student.displayInfo();
return 0;
}
4 . Develop a c++ program for a bank employee to print name of the
employee , acc_no and balance. Print invalid balance if amount < 500 ,
Display the same , also display the balance after withdraw and deposit .
#include <iostream>
#include <string>
class BankEmployee
private:
string employeeName;
int accountNumber;
float balance;
public:
void inputDetails()
cin>>employeeName;
// Validate balance
void displayDetails()
balance -= amount;
cout << "Withdraw successful. Updated balance: " << balance << endl;
else
if (amount > 0)
balance += amount;
cout << "Deposit successful. Updated balance: " << balance << endl;
else
};
int main()
BankEmployee employee;
employee.inputDetails();
employee.displayDetails();
employee.withdraw(200);
employee.deposit(1000);
employee.displayDetails();
return 0;