Monday, July 15, 2024

Simple Calculator Using Abstraction in C++

Simple Calculator Using Abstraction in C++

 


Program Listing

#include <iostream>


// Abstract class for calculator operations

class Operation {

public:

    virtual double calculate(double a, double b) = 0;

};


// Concrete subclasses for each operation

class Addition : public Operation {

public:

    double calculate(double a, double b) override {

        return a + b;

    }

};


class Subtraction : public Operation {

public:

    double calculate(double a, double b) override {

        return a - b;

    }

};


class Multiplication : public Operation {

public:

    double calculate(double a, double b) override {

        return a * b;

    }

};


class Division : public Operation {

public:

    double calculate(double a, double b) override {

        if (b == 0) {

            std::cerr << "Error: Division by zero is not allowed." << std::endl;

            return 0; // Return 0 as an error value

        }

        return a / b;

    }

};


int main() {

    double num1, num2;

    char operation;


    std::cout <<"\n\n\tSimple Calculator Using Abstraction in C++\n";

    std::cout << "\n\tGive two numbers: ";

    std::cin >> num1 >> num2;


    std::cout << "\tEnter the operation (+, -, *, /): ";

    std::cin >> operation;


    Operation* op = nullptr;


    switch (operation) {

        case '+':

            op = new Addition();

            break;

        case '-':

            op = new Subtraction();

            break;

        case '*':

            op = new Multiplication();

            break;

        case '/':

            op = new Division();

            break;

        default:

            std::cerr << "\tError: Invalid operation." << std::endl;

            return 1;

    }


    double result = op->calculate(num1, num2);


    std::cout << "\n\tThe Result: " << result << std::endl;

     std::cout << "\n\n\tEnd of Program. Thank you for using this program." << std::endl;

    delete op;


    return 0;

}


Sunday, July 14, 2024

Empower Your Business with My IT Consulting Services!

Empower Your Business with My IT Consulting Services!

 


Empower Your Business with My IT Consulting Services!


Are you navigating the complexities of modern technology? Gain a competitive edge with tailored IT solutions crafted to meet your unique business challenges. As a seasoned consultant specializing in Computer Organization, Operating Systems, and Database Systems, I provide strategic guidance and hands-on expertise to drive your business forward.


** My Services Offered:**


- **Strategic IT Planning:** Align technology with your business goals for sustainable growth and efficiency.

- **Infrastructure Assessment and Optimization:** Enhance performance and reliability through streamlined infrastructure solutions.


- **Security and Compliance:** Safeguard your assets with robust cybersecurity measures and regulatory compliance strategies.


- **Cloud Integration and Migration:** Harness the power of cloud technologies for scalability and cost-efficiency.


- **IT Project Management:** From inception to completion, ensure smooth project execution and delivery.


Partner with me to transform challenges into opportunities. Contact today to discuss how I can optimize your IT infrastructure and propel your business to new heights.


Feel free to personalize it further to highlight specific achievements, client successes, or industry expertise that set you apart! You may contact me here in the Philippines at

my mobile number 09173084360 and my email address at

jakerpomperada@gmail.com


Dr. Jake R. Pomperada,MAED-IT,MIT, PHD-TM

Freelance IT Consultant


What is Risk Management?

What is Predictive Analytics?

Importance of Data Science

Thursday, July 11, 2024

What is Augmented Reality?

Difference of Two Numbers in C

 



Program Listing

#include <stdio.h>


int main()

{   

    int a=0,b=0,difference=0;

    printf("\n\n");

printf("\tDifference of Two Numbers in C");

printf("\n\n");

printf("\tGive Two Numbers : ");

    scanf("%d%d",&a,&b);


    /* Compute the Difference of Two Numbers */

    

    difference = (a - b);

    

printf("\n\n");

printf("\t===== DISPLAY RESULTS =====");

printf("\n\n");

printf("\tThe difference between %d and %d is %d.",a,b,difference);

printf("\n\n");

printf("\tEnd of Program");

printf("\n");

}


Wednesday, July 10, 2024

What is cash flow statement?

What is income statement?

Student Record System in C++

Student Record System in C++


 


Program Listing

#include <iostream>

#include <string>


class Student {

public:

    // Constructor to initialize the student's information

    Student(std::string name, int rollNumber, double marks) {

        this->name = name;

        this->rollNumber = rollNumber;

        this->marks = marks;

    }


    // Function to display the student's information

    void displayInfo() {

        std::cout << "\n\tStudent Name: " << name << std::endl;

        std::cout << "\tRoll Number: " << rollNumber << std::endl;

        std::cout << "\tMarks: " << marks << std::endl;

    }


private:

    std::string name;

    int rollNumber;

    double marks;

};


int main() {

    std::string name;

    int rollNumber;

    double marks;


    // Input student information

    std::cout <<"\n";

    std::cout << "\tEnter student's name: ";

    std::cin >> name;


    std::cout << "\tEnter roll number: ";

    std::cin >> rollNumber;


    std::cout << "\tEnter marks: ";

    std::cin >> marks;


    // Create a Student object with the provided information

    Student student(name, rollNumber, marks);


    char choice;

    

    do {

        std::cout << "\n\tStudent Record Main Menu\n" << std::endl;

        std::cout << "\t[1] Display student information" << std::endl;

        std::cout << "\t[2] Quit Program" << std::endl;

        std::cout << "\tEnter your choice: ";

        std::cin >> choice;


        if (choice == '1') {

            // Display the student's information

            student.displayInfo();

        } else if (choice != '2') {

            std::cout << "\n\tInvalid choice. Please try again." << std::endl;

        }


    } while (choice != '2');

     std::cout << "\n\tEnd of Program. Thank you for using this program." << std::endl;

    return 0;

}