Learn Computer Programming Free from our source codes in my website.
Sponsored Link Please Support
https://www.techseries.dev/a/27966/qWm8FwLb
https://www.techseries.dev/a/19181/qWm8FwLb
My Personal Website is http://www.jakerpomperada.com
Email me at jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Monday, July 8, 2024
Saturday, July 6, 2024
Thursday, July 4, 2024
Wednesday, July 3, 2024
Tuesday, July 2, 2024
Monday, July 1, 2024
Sunday, June 30, 2024
Bank Account in C++
Program Listing
#include <iostream>
#include <iomanip>
class BankAccount {
private:
double balance;
public:
BankAccount() : balance(0.0) {}
void deposit(double amount) {
if (amount > 0) {
balance += amount;
std::cout << "\tDeposited PHP" <<std::fixed <<std::setprecision(2) << amount << ". New balance: PHP" << balance << std::endl;
} else {
std::cout << "\tInvalid deposit amount." << std::endl;
}
}
void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
std::cout << "\tWithdrawn PHP" <<std::fixed <<std::setprecision(2)<< amount << ". New balance: PHP" << balance << std::endl;
} else {
std::cout << "\tInvalid withdrawal amount or insufficient funds." << std::endl;
}
}
double getBalance() const {
return balance;
}
};
int main() {
BankAccount account;
int choice=0;
double amount=0.00;
while (true) {
std::cout << "\n\tBank Account Main Menu" << std::endl;
std::cout << "\t[1] Deposit Money" << std::endl;
std::cout << "\t[2] Withdraw Money" << std::endl;
std::cout << "\t[3] Check Balance" << std::endl;
std::cout << "\t[4] Quit Program" << std::endl;
std::cout << "\n\tEnter your choice: ";
std::cin >> choice;
switch (choice) {
case 1:
std::cout << "\tEnter the deposit amount: PHP";
std::cin >> amount;
account.deposit(amount);
break;
case 2:
std::cout << "\tEnter the withdrawal amount: PHP";
std::cin >> amount;
account.withdraw(amount);
break;
case 3:
std::cout << "\tCurrent balance: PHP" <<std::fixed <<std::setprecision(2)<< account.getBalance() << std::endl;
break;
case 4:
std::cout << "\tExiting. Thank you for using this program." << std::endl;
return 0;
default:
std::cout << "\tInvalid choice. Please try again." << std::endl;
}
}
return 0;
}
Friday, June 28, 2024
Temperature Converter Using Encapsulation in C++
#include <iostream>
class TemperatureConverter {
private:
double celsius;
double fahrenheit;
public:
TemperatureConverter() : celsius(0.0), fahrenheit(32.0) {}
void setCelsius(double c) {
celsius = c;
fahrenheit = (celsius * 9.0/5.0) + 32.0;
}
void setFahrenheit(double f) {
fahrenheit = f;
celsius = (fahrenheit - 32.0) * 5.0/9.0;
}
double getCelsius() const {
return celsius;
}
double getFahrenheit() const {
return fahrenheit;
}
};
int main() {
TemperatureConverter converter;
std::cout << "\n\tTemperature Converter Using Encapsulation in C++\n\n";
// Convert from Celsius to Fahrenheit
converter.setCelsius(35.0);
std::cout << "\t35 degrees Celsius is equal to " << converter.getFahrenheit() << " degrees Fahrenheit.\n";
// Convert from Fahrenheit to Celsius
converter.setFahrenheit(112.3);
std::cout << "\n\tEnd of Program\n\n";
return 0;
}