c++ to find sum of odd
#include <iostream>class OddNumberSum {public: int calculateSum() { int sum = 0; for (int i = 1; i <= 100; ++i) { if (i % 2 != 0) { sum += i; } } return sum; }};int main() { OddNumberSum oddSumCalculator; int result = oddSumCalculator.calculateSum(); std::cout << "Sum of odd numbers from 1 to 100: " << result << std::endl; return 0;}
bank acc
#include <iostream>class Account {private: int accountNumber; double accountBalance;public: Account(int accNum, double accBal) : accountNumber(accNum), accountBalance(accBal) {} double getAccountBalance() const { return accountBalance; } void deposit(double amount) { accountBalance += amount; } void withdraw(double amount) { if (amount <= accountBalance) { accountBalance -= amount; } else { std::cout << "Insufficient funds. Withdrawal not allowed." << std::endl; } }};int main() { Account myAccount(12345, 1000.0); std::cout << "Initial Account Balance: $" << myAccount.getAccountBalance() << std::endl; myAccount.deposit(500.0); std::cout << "After Deposit, Account Balance: $" << myAccount.getAccountBalance() << std::endl; myAccount.withdraw(200.0); std::cout << "After Withdrawal, Account Balance: $" << myAccount.getAccountBalance() << std::endl; myAccount.withdraw(1500.0); return 0;}
c ++ prog to calculate volume of box
#include <iostream>class Volume {private: double length; double breadth; double height;public: Volume(double l, double b, double h) : length(l), breadth(b), height(h) {} double calculateVolume() { return length * breadth * height; }};int main() { double length, breadth, height; std::cout << "Enter the length of the box: "; std::cin >> length; std::cout << "Enter the breadth of the box: "; std::cin >> breadth; std::cout << "Enter the height of the box: "; std::cin >> height; Volume box(length, breadth, height); double result = box.calculateVolume(); std::cout << "Volume of the box: " << result << std::endl; return 0;}