0% found this document useful (0 votes)
5 views2 pages

C++ Lab Assignment Part3

The document contains three C++ programs: the first reverses the first and last names entered by the user, the second implements a four-function calculator that performs basic arithmetic operations, and the third defines a Bank class for managing customer accounts, allowing for account assignment, deposits, withdrawals, and display of account details for up to 10 customers.

Uploaded by

brishalraj2006
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)
5 views2 pages

C++ Lab Assignment Part3

The document contains three C++ programs: the first reverses the first and last names entered by the user, the second implements a four-function calculator that performs basic arithmetic operations, and the third defines a Bank class for managing customer accounts, allowing for account assignment, deposits, withdrawals, and display of account details for up to 10 customers.

Uploaded by

brishalraj2006
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/ 2

Q15: Reverse First and Last Name

#include <iostream>
#include <string>
using namespace std;

int main() {
string first, last;
cout << "Enter first name: ";
cin >> first;
cout << "Enter last name: ";
cin >> last;

string reversed = last + " " + first;


cout << "Reversed Name: " << reversed << endl;

return 0;
}

Q16: Four Function Calculator


#include <iostream>
using namespace std;

int main() {
float a, b, result;
char op, choice;

do {
cout << "Enter first number: ";
cin >> a;
cout << "Enter operator (+, -, *, /): ";
cin >> op;
cout << "Enter second number: ";
cin >> b;

switch (op) {
case '+': result = a + b; break;
case '-': result = a - b; break;
case '*': result = a * b; break;
case '/':
if (b != 0)
result = a / b;
else {
cout << "Division by zero error!" << endl;
continue;
}
break;
default:
cout << "Invalid operator!" << endl;
continue;
}
cout << "Result: " << result << endl;

cout << "Do another calculation? (y/n): ";


cin >> choice;
} while (choice == 'y' || choice == 'Y');

return 0;
}

Q17: Bank Account Class for 10 Customers


#include <iostream>
using namespace std;

class Bank {
string name, accType;
int accNo;
float balance;

public:
void assign() {
cout << "Enter Name, Account Number, Type, Balance: ";
cin >> name >> accNo >> accType >> balance;
}

void deposit(float amount) {


balance += amount;
}

void withdraw(float amount) {


if (balance >= amount)
balance -= amount;
else
cout << "Insufficient balance!" << endl;
}

void display() {
cout << "Name: " << name << ", Account No: " << accNo
<< ", Type: " << accType << ", Balance: " << balance << endl;
}
};

int main() {
Bank customer[10];
for (int i = 0; i < 10; i++) {
cout << "Customer " << i + 1 << ":
";
customer[i].assign();
}

cout << "\nDisplaying customer details:\n";


for (int i = 0; i < 10; i++) {
customer[i].display();
}

return 0;
}

You might also like