C
C
#include <iostream>
#include <string>
// Function to greet based on provided name and greeting (with default value)
std::cout << greeting << ", " << name << std::endl;
int main() {
// Example usage
return 0;
Q2.
#include <iostream>
#include <string>
#include <vector>
class Student {
private:
std::string name;
int age;
std::vector<double> grades;
public:
// Destructor
~Student() {
std::cout << "Destroying student: " << name << std::endl;
grades.push_back(grade);
if (grades.empty()) {
sum += grade;
};
int main() {
// Create a student
Student alice("Alice", 20);
alice.addGrade(85.5);
alice.addGrade(92.0);
alice.addGrade(78.3);
alice.printDetails();
return 0;
Q4.
#include <iostream>
#include <vector>
class Matrix {
private:
std::vector<std::vector<double>> data;
int rows;
int cols;
public:
// Copy constructor
data[row][col] = value;
} else {
std::cerr << "Matrix dimensions must match for addition." << std::endl;
return result;
};
int main() {
// Example usage
A.setElement(0, 0, 1.0);
A.setElement(0, 1, 2.0);
A.setElement(0, 2, 3.0);
A.setElement(1, 0, 4.0);
A.setElement(1, 1, 5.0);
A.setElement(1, 2, 6.0);
A.display();
B.display();
C.display();
return 0;
Q3.
#include <iostream>
#include <vector>
#include <string>
class Account {
private:
string accountNumber;
double balance;
public:
// Constructor to initialize account
: accountNumber(accNum), balance(initialBalance) {}
if (amount > 0) {
balance += amount;
} else {
balance -= amount;
} else {
return balance;
return accountNumber;
};
private:
string name;
string address;
vector<Account> accounts;
public:
: name(custName), address(custAddress) {}
accounts.push_back(account);
};
class Bank {
private:
vector<Customer> customers;
public:
customer.displayCustomerInfo();
};
int main() {
cust1.addAccount(acc1);
cust1.addAccount(acc2);
Bank myBank;
myBank.addCustomer(cust1);
acc1.deposit(200);
acc1.withdraw(150);
acc2.deposit(100);
acc2.withdraw(50);
myBank.displayAllCustomers();
return 0;