Answer to Question #207300 in C++ for kamran

Question #207300

 Write Syntax for each of the following in C++ environment: i. Function Declaration ii. Function Definition iii. Function Overloading 


1
Expert's answer
2021-06-16T00:59:44-0400
#include <iostream>
using namespace std;


int fun(int a, int b); //function declaration
int fun(int a, int b, int c);  //overloaded function declaration


//function definition
int fun(int a, int b){
	cout<<"This function accepts two arguments and returns their sum."<<endl;
	cout<<"The arguments are: "<<a<<" "<<b<<endl;
	return (a+b);
}


//overloaded function definition
int fun(int a, int b, int c){
	cout<<"This function accepts three arguments and returns their sum."<<endl;
	cout<<"The arguments are: "<<a<<" "<<b<<" "<<c<<endl;
	return (a+b+c);
}


int main(){
	//this is main function
	int a, b, c, s;
	cout<<"Enter value of a, b, c in order: ";
	cin>>a>>b>>c;
	cout<<"Calling function with two arguments."<<endl;
	s = fun(a, b);
	cout<<"Sum of a, b: "<<s<<"\n";
	cout<<"Calling function with three arguments."<<endl;
	s = fun(a, b, c);
	cout<<"Sum of a, b, c: "<<s<<"\n";
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog