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;
}