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
Tuesday, October 29, 2024
Monday, October 28, 2024
Saturday, October 26, 2024
Thursday, October 24, 2024
Wednesday, October 23, 2024
Temperature Converter Using a Class in Python
Program Listing
class TemperatureConverter:
@staticmethod
def celsius_to_fahrenheit(celsius):
return (celsius * 9 / 5) + 32
@staticmethod
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5 / 9
celsius_temperature = 34.36
fahrenheit_temperature = 134.98
print("\n\tTemperature Converter Using a Class in Python\n")
print("\tCelsius to Fahrenheit: {:.2f}°C = {:.2f}°F".format(celsius_temperature, TemperatureConverter.celsius_to_fahrenheit(celsius_temperature)))
print("\tFahrenheit to Celsius: {:.2f}°F = {:.2f}°C".format(fahrenheit_temperature, TemperatureConverter.fahrenheit_to_celsius(fahrenheit_temperature)))
print("\n\tEnd of Program. Thank you for Using This Program\n")
Monday, October 21, 2024
Simple Calculator Using a Class in Python
Program Listing
class Calculator:
def __init__(self):
print("\n\tSimple Calculator Using a Class in Python\n\n")
def get_user_input(self):
self.num1 = float(input("\tEnter the first number: "))
self.operator = input("\tEnter the operator (+, -, *, /): ")
self.num2 = float(input("\tEnter the second number: "))
def calculate_result(self):
if self.operator == '+':
self.result = self.num1 + self.num2
elif self.operator == '-':
self.result = self.num1 - self.num2
elif self.operator == '*':
self.result = self.num1 * self.num2
elif self.operator == '/':
if self.num2 != 0:
self.result = self.num1 / self.num2
else:
print("\tError: Division by zero is not allowed.")
exit(1)
else:
print("\tError: Invalid operator")
exit(1)
def display_result(self):
print("\n\tThe Result is ", self.result, ".")
print("\n\tEnd of Program")
# Create an instance of the Calculator class
calculator = Calculator()
# Get user input
calculator.get_user_input()
# Calculate and display the result
calculator.calculate_result()
calculator.display_result()
Thursday, October 17, 2024
Wednesday, October 16, 2024
Tuesday, October 15, 2024
Monday, October 14, 2024
Sunday, October 13, 2024
Friday, October 11, 2024
Wednesday, October 9, 2024
Tuesday, October 8, 2024
Monday, October 7, 2024
Thursday, October 3, 2024
Animals Sound Using Polymorphism in C++
Program Listing
#include <iostream>
class Animal {
public:
virtual void makeSound() {
std::cout << "The animal makes a sound." << std::endl;
}
};
class Dog : public Animal {
public:
void makeSound() override {
std::cout << "\tThe dog barks." << std::endl;
}
};
class Snake : public Animal {
public:
void makeSound() override {
std::cout << "\tThe snake ssshh." << std::endl;
}
};
class Cat : public Animal {
public:
void makeSound() override {
std::cout << "\tThe cat meows." << std::endl;
}
};
int main() {
Animal* animals[3];
animals[0] = new Dog();
animals[1] = new Cat();
animals[2] = new Snake();
std::cout <<"\n\n\tAnimals Sound Using Polymorphism in C++\n\n";
for (int i = 0; i < 3; i++) {
std::cout << "\tAnimal " << i + 1 << ": ";
animals[i]->makeSound();
}
// Don't forget to delete the dynamically allocated objects to free memory.
for (int i = 0; i < 3; i++) {
delete animals[i];
}
std::cout << "\n\tEnd of Program. Thank you for using this program." << std::endl;
return 0;
}
Wednesday, October 2, 2024
Sunday, September 29, 2024
Saturday, September 28, 2024
Friday, September 27, 2024
Monday, September 23, 2024
Friday, September 20, 2024
Thursday, September 19, 2024
Wednesday, September 18, 2024
Tuesday, September 17, 2024
Sunday, September 15, 2024
Saturday, September 14, 2024
Friday, September 13, 2024
Wednesday, September 11, 2024
Tuesday, September 10, 2024
Monday, September 9, 2024
Sunday, September 8, 2024
Student Records Using Encapsulation in Python
Student Records Using Encapsulation in Python
ScreenshotProgram Listing
class Student:
self.name = student_name
self.age = student_age
self.grade = student_grade
def get_name(self):
return self.name
def get_age(self):
return self.age
def get_grade(self):
return self.grade
def set_name(self, student_name):
self.name = student_name
def set_age(self, student_age):
self.age = student_age
def set_grade(self, student_grade):
self.grade = student_grade
if __name__ == "__main__":
student = Student("Julianna Rae Pomperada", 16, 92)
print("\n\tStudent Records Using Encapsulation in Python")
print("\n\tDisplay Student Record\n")
print("\tStudent Name: " + student.get_name())
print("\tStudent Age: " + str(student.get_age()) + " years")
print("\tStudent Grade: " + str(student.get_grade()))
student.set_name("Jacob Samuel Pomperada")
student.set_age(18)
student.set_grade(88)
print("\n\tUpdated Student Record\n")
print("\tStudent Name: " + student.get_name())
print("\tStudent Age: " + str(student.get_age()) + " years old.")
print("\tStudent Grade: " + str(student.get_grade()))
print("\n\tEnd of Program. Thank you for using this program.")
Friday, September 6, 2024
Thursday, September 5, 2024
Wednesday, September 4, 2024
Tuesday, September 3, 2024
Monday, September 2, 2024
Sunday, September 1, 2024
Friday, August 30, 2024
Tuesday, August 27, 2024
Monday, August 26, 2024
Saturday, August 24, 2024
Thursday, August 22, 2024
Wednesday, August 21, 2024
Tuesday, August 20, 2024
Monday, August 19, 2024
Sunday, August 18, 2024
Saturday, August 17, 2024
Friday, August 16, 2024
Thursday, August 15, 2024
Wednesday, August 14, 2024
Addition and Subtraction of Two Numbers Using Polymorphism in JavaScript
Program Listing