Respuesta :
Answer:
The answer to this question is "yes" and the program to this question can be given as:
Program:
#include <iostream> //include header file
using namespace std; //using namespace
class ab //define class
{
public: //access modifier
int i,tab; //defining variable.
void table(int n) //define method
{
for(i=1; i<=10; i++) //define loop.
{
tab=n*i; //calculate table.
cout<<tab<<endl; //print values.
}
}
};
int main() //define main method.
{
int n; //defining variable
cout<<"Enter any number :"; //message
cin>> n; //input number by user.
cout<<"Table of :" <<n<<endl; //message
ab ob; //creating class object.
ob.table(n); //calling function.
return 0;
}
Output:
Enter any number :2
Table of :2
2
4
6
8
10
12
14
16
18
20
Explanation:
- In the above c++ program firstly defines a class that is "ab" inside the class two integer variable is defined that is " i and tab".
- Then a function that is table() is defined, which takes a value n in its parameter. This function doesn't return any value. Inside the function, a for loop is define that calculates the table of the given number and prints its value.
- In the main method, an integer variable n is defined that takes value-form user and pass into the function. In the main method, we create the class object that is "ob" and with the help of an object we call the function that prints table of a given number.