CALCULATOR in c++ with implementation of OOP

It's my school assignment
i have to implement c++ in OOP
Urgent need to submit this morning :(

calculator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #ifndef CALCULATOR_H
#define CALCULATOR_H

class Calculator
{
	private:
		int option;
		double num1, num2;
	
	public:
		Calculator(){}
		int selectOption();
		void setOption(int option);
		int getOption();
};
#endif 


calculator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
#include "Calculator.h"

using namespace std;

int Calculator::selectOption;
{
	switch(option)
	{
		case 1:
		Cout<<"Addition"<<num1 + num2;
		break;
		
		case 2:
		Cout<<"Substraction"<<num1 - num2;
		break;
		
		case 1:
		Cout<<"Multiplication"<<num1 * num2;
		break;
		
		case 1:
		Cout<<"Division"<<num1 / num2;
		break;
	}
	
	void Calculator::setOption(int option)
	{
		this -> option = option;
	}
	
	int Calculator::getOption()
	{
		return this -> option;
	}
	
}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
#include"Calculator.h"

using namespace std;

int main()
{
	Calculator kalkulator;
	int option;
	double num1, num2;
	
	cout<<"This system work as a Calculator";
	
	cout<<"Enter Num 1";
	cin>>num1;
	
	cout<<"Enter Num 1";
	cin>>num1;
	
	cout<<"Please Select your Operator";
	cout<<"\n 1-Addition \n 2-Subtraction \n 3-Multiplication \n 4-Division";
	cin>>option;
	
	kalkulator.setOption(option);
	option = kalkulator.selectOption();
	
}
Last edited on
closed account (1vf9z8AR)
but what is your issue?
issue is here:

calculator.cpp:6:17: error: ‘int Calculator::selectOption’ is not a static data member of ‘class Calculator’
int Calculator::selectOption;
^~~~~~~~~~~~
calculator.cpp:7:1: error: expected unqualified-id before ‘{’ token
{
int Calculator::selectOption;
should be
int Calculator::selectOption()
However, if you're planning to return the result of a division, you'd better to return a double.

At first glance, it seems you're not passing the user input to your class instance - I don't think it can work that way.
Topic archived. No new replies allowed.