Write a C++ program that can take either two integers or two floating point numbers and outputs the smallest number using class, friend functions and function overloading.

Recommended Answers

All 4 Replies

What have you tried so far? We don't do homeworks for people here. You have to show some efforts and ask about some specific problems that you are having with your own code.

I have the code ready... Let me know when you need it so i can post it here for you ok? Read the FAQ's first anyway ok?

Member Avatar for ArashVenus
/* Writing a simple program for comparing 2 integers */
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
    int a = 0;
    int b = 0;       /* You can also use double or other types here */
    /* I should note that you must initialize your variables or else you will end up having Access Violation errors */

    cout << "Please enter A then press Enter : ";
    cin >> a;
    cout << "Please enter B then press Enter : ";
    cin >> b;

    /* Comparing a to b and writing the smallest number on output */
    if (a < b) cout << "The smallest number is : " << a;
    else cout << "The smallest number is : " << b;
    return 0;
}

If you study your books well enough , you will have a clue how to convert this to an object-oriented program :-)

Q2: Write a C++ program that prompts the user to insert two integers to send them to a function that will return the Greatest Common Division (GCD) )
note: using function

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.