write a program in c++ to overload the function add (s1,s2)
where s1 and s2 are integers and floating point values.
Answers were Sorted based on User's Feedback
Answer / deepa mathur
include <iostream.h>
void add (int s1, int s2)
{
int s3;
s3= s1 + s2;
cout<<"sum of 2 no. is= "<< s3;
}
void add (float s1, float s2)
{
float s3;
s3 = s1 + s2;
cout<<" sum of 2 no. is= "<< s3;
}
void main
{
void add (int a, int b);
void add (float a, float b);
add(30, 20);
add (30.5, 56.7);
getch();
}
Is This Answer Correct ? | 47 Yes | 20 No |
Answer / rose
include<iostream.h>
class overload
{
void add (int a, int b){
int c;
int c= a+b;
}
void add( float a,float b){
double c;
double c = a+b;}
}
void main()
{overload o = new overload();
o.add(10,20);
o.add(1.2,34.56);
getch();
}
Is This Answer Correct ? | 14 Yes | 10 No |
Answer / vaibhav munde
#include<iostream.h>
#include<conio.h>
int add(int s1,int s2)
{
return(s1+s2);
}
float add(float a,float b)
{
return(a+b);
}
void main()
{
int s,s1,s2;
float a,b,c;
clrscr();
cout<<"\n Enter two integer number:";
cin>>s1>>s2;
s=add(s1,s2);
cout<<"Addition of two Integer number:"<<s;
out<<"\n Enter two float number:";
cin>>a>>b;
c=add(a,b);
cout<<"Addition of two Float number:"<<c;
getch();
}
Is This Answer Correct ? | 12 Yes | 8 No |
Answer / shubham hajare
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
class stud
{
public:
void add(int a,int b)
{
cout<<a+b;
}
void add(float a,float b)
{
cout<<a+b;
}
void add(int a,float b)
{
cout<<a+b;
}
};
void main()
{
stud a;
a.add(12,12);
a.add(1.2,1.2);
a.add(12,12.2);
_getch();
}
Is This Answer Correct ? | 3 Yes | 3 No |
What are the advantages of inheritance?
26 Answers IBS, TCS,
What is the difference between an object and a class?
Finding of the 4 larger (bigger) numbers from the list like{1245,4587,2145,1163,29987,65783.....}
What is oops concept with example?
What is purpose of inheritance?
what is difference between String s=new String("vali"); String s="vali"
why function overloading is not called as pure polymorphism?
What is new keyword in oops?
what is difference between c++ language and java language
What is methods in oop?
When you define a integer it gets stored in which data structure?(Stack or a heap)
What is the difference between inheritance and polymorphism?