#include<iostream>
using namespace std;
class addSub{
public:
int num1, num2;
void inPut(){
cout<<"Enter two values: "<<endl;
cin>>num1>>num2;
}
void sum()
{
int s = num1 + num2;
cout<<"Summation is: "<<s<<endl;
}
void sub()
{
int s = num1 - num2;
cout<<"Subtraction is: "<<s<<endl;
}
};
int main()
{
addSub obj;
int n;
cout<<"Press 1 for summation, 2 for subtraction: ";
while(cin>>n){
obj.inPut();
if(n == 1){
obj.sum();
}
else if(n == 2){
obj.sub();
}
}
return 0;
}
Sunday, October 18, 2020
Addition subtraction using class and object in C++
Sunday, October 4, 2020
Major parts of a C program with proper example, 52D Batch
/* Author: Alamgir Hossain Date: 5/10/2020 Purpose: to knowing major parts of a c program */// 1. Documentation part/documentation section #include<stdio.h>//2. Linking part/Section //#define x 50 //3. Definition Section #define square(n) n * n #define summation(num1, num2) num1 + num2//Macro int p = 50;//4. Global Declaration Section/Part char ch = 'z'; int multiply(int num1, int num2)//5. sub-program section { int res = num1 * num2; return res; } void prime(){ printf("Welcome to Prime University\n"); } int main()//6. Main program section/part { int x, y, r; x = 100; y = 200; printf("%d\n", x); prime(); r = square(5);//Macro Calling // printf("%d\n", res); printf("%d\n", p); return 0; }