Computer Science, asked by gurpreetduggal98763, 9 months ago

write a program that uses same function name as the name of class to get two input value from user and display the values?​

Answers

Answered by Anonymous
0

Answer:

A function is a set of statements that take inputs, do some specific computation ... Functions make code modular. ... ( parameter names are not there in below declarations).

Answered by AskewTronics
0

Below are the program for the above question:-

Explanation:

#include <iostream> // header file.

using namespace std;  //package name.

class function1  //class name

{

   public:  //access specifier

  function1()  //function name or can be called as Constructor.

   {

       int firstnumber, secondnumber;  //two variables declaration

       cin>>firstnumber>>secondnumber;  //take input value

       cout<<"The value are "<<firstnumber<<" and "<<secondnumber;  //give the output as input value.

   }

};

int main()  //main function

{

     function1 object1;    //class object.

     return 0;

}

Output:

  • If the user take inputs as 4 and 5 then the output is 4 and 5.
  • If the user take inputs as 6 and 7 then the output is 6 and 7.

Code Explanation:

  • The above code is in c++ language which takes the two values as input and prints the value.
  • There is a function which has the same name which the class has. But this type of function is known as a Constructor and can be called when the object of that class is declared.

Learn More:

  • Constructors: https://brainly.in/question/7573450
Similar questions