0% found this document useful (0 votes)
105 views8 pages

C++ Lab Programs

The document contains 4 C++ programs: 1) Finds the largest of three numbers entered by the user. 2) Sorts an array of numbers in ascending and descending order. 3) Defines a Student class to display student name, roll number, marks in two subjects, and total score. 4) Defines a BankEmployee class to input employee details, display account details, and perform withdraw and deposit transactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views8 pages

C++ Lab Programs

The document contains 4 C++ programs: 1) Finds the largest of three numbers entered by the user. 2) Sorts an array of numbers in ascending and descending order. 3) Defines a Student class to display student name, roll number, marks in two subjects, and total score. 4) Defines a BankEmployee class to input employee details, display account details, and perform withdraw and deposit transactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

Develop a C++ program to find the largest of three numbers

#include <iostream>

using namespace std;

int main()

float num1, num2, num3;

cout << "Enter three numbers: ";

cin >> num1 >> num2 >> num3;

if (num1 >= num2 && num1 >= num3)

cout << "Largest number: " << num1;

else if (num2 >= num1 && num2 >= num3)

cout << "Largest number: " << num2;

else

cout << "Largest number: " << num3;

return 0;

}
2. Develop a C++ program to sort the elements in ascending and descending order

#include<iostream.h>

using namespace std;

void ascDecFunc(int a[], int n)

int temp;

for(int i=0;i < n-1;i++)

for(int j = 0;j < n/2; j++) { if(a[j]>a[j+1])

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

for(int j = n/2;j < n-1; j++)

if(a[j] < a[j+1])

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}
}

for(int i = 0; i < n; i++)

cout<<a[i]<<" ";

int main()

int arr[] = {3, 2, 4, 1, 10, 30, 40, 20};

int len = sizeof(arr) / sizeof(arr[0]);

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>

using namespace std;

class Student

private:

string name;

int rollNumber;

float marksSubject1;

float marksSubject2;

public:

void inputDetails()

cout << "Enter student name: ";

cin>> name;

cout << "Enter roll number: ";

cin >> rollNumber;

cout << "Enter marks in Subject 1: ";

cin >> marksSubject1;

cout << "Enter marks in Subject 2: ";

cin >> marksSubject2;

}
// Function to calculate and display total score

void displayInfo()

cout << "\nStudent Information:\n";

cout << "Name: " << name << endl;

cout << "Roll Number: " << rollNumber << endl;

cout << "Marks in Subject 1: " << marksSubject1 << endl;

cout << "Marks in Subject 2: " << marksSubject2 << endl;

float totalScore = marksSubject1 + marksSubject2;

cout << "Total Score: " << totalScore << endl;

};

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>

using namespace std;

class BankEmployee

private:

string employeeName;

int accountNumber;

float balance;

public:

// Function to input employee details

void inputDetails()

cout << "Enter employee name: ";

cin>>employeeName;

cout << "Enter account number: ";

cin >> accountNumber;

cout << "Enter initial balance: ";

cin >> balance;

// Validate balance

if (balance < 500)

cout << "Invalid balance! Balance should be at least 500.\n";

balance = 0; // Reset balance to 0 for invalid input


}

// Function to display account details

void displayDetails()

cout << "\nEmployee Details:\n";

cout << "Name: " << employeeName << endl;

cout << "Account Number: " << accountNumber << endl;

cout << "Balance: " << balance << endl;

// Function to perform withdraw operation

void withdraw(float amount)

if (amount > 0 && amount <= balance)

balance -= amount;

cout << "Withdraw successful. Updated balance: " << balance << endl;

else

cout << "Invalid withdraw amount or insufficient balance.\n";

// Function to perform deposit operation

void deposit(float amount)


{

if (amount > 0)

balance += amount;

cout << "Deposit successful. Updated balance: " << balance << endl;

else

cout << "Invalid deposit amount.\n";

};

int main()

BankEmployee employee;

employee.inputDetails();

employee.displayDetails();

employee.withdraw(200);

employee.deposit(1000);

employee.displayDetails();

return 0;

You might also like