0% found this document useful (0 votes)
32 views2 pages

Numbers A B Readnumbers Printnumbers Caladdition

The document describes a C++ program that defines a Numbers class to calculate the addition of two numbers. The Numbers class contains member functions to read in two numbers, print the numbers, and calculate their addition. The main function declares a Numbers object, takes input using the readNumbers function, calculates the addition using calAddition, and prints the output.

Uploaded by

gniz gunoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Numbers A B Readnumbers Printnumbers Caladdition

The document describes a C++ program that defines a Numbers class to calculate the addition of two numbers. The Numbers class contains member functions to read in two numbers, print the numbers, and calculate their addition. The main function declares a Numbers object, takes input using the readNumbers function, calculates the addition using calAddition, and prints the output.

Uploaded by

gniz gunoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Addition of two numberusing class

#include <iostream>
using namespace std;

//class definition
class Numbers
{
private:
int a;
int b;
public:
//member function declaration
void readNumbers(void);
void printNumbers(void);
int calAddition(void);
};

//member function definitions


void Numbers::readNumbers(void)
{
cout<<"Enter first number: ";
cin>>a;
cout<<"Enter second number: ";
cin>>b;
}

void Numbers::printNumbers(void)
{
cout<<"a= "<<a<<",b= "<<b<<endl;
}

int Numbers::calAddition(void)
{
return (a+b);
}

//main function
int main()
{
//declaring object
Numbers num;
int add; //variable to store addition
//take input
num.readNumbers();
//find addition
add=num.calAddition();

//print numbers
num.printNumbers();
//print addition
cout<<"Addition/sum= "<<add<<endl;
return 0;
}
Output
Enter first number: 100
Enter second number: 200
a= 100,b= 200
Addition/sum= 300

You might also like