#include <iostream>
#include "multiplication.h"
#include "subtraction.h"
using namespace std;
int main() {
multiplication out;
subtraction out2;
int x, y, z;
int product;
int difference;
cout << "Enter two numbers to multiply by: ";
cin >> x;
cin >> y;
product = out.mult();
cout << "the product is: " << product;
cout << "Now enter a number to subtract the product by: ";
cin >> z;
difference = out2.sub();
cout << "the difference is: " << difference;
}
#pragma once
class multiplication
{
public:
int mult();
};
#include <iostream>
using namespace std;
#include "multiplication.h"
int multiplication::mult(int x, int y) {
return x * y;
}
#pragma once
class subtraction
{
public:
int sub();
};
#include <iostream>
using namespace std;
#include "subtraction.h"
int subtraction::sub(int product, int z) {
return product - z;
}
我需要将用户输入变量从main传递到mult,将用户输入z和product从main传递给sub。我在创建的函数中尝试将它们作为args传递,但它们没有被访问。
编辑:我加了乘法和减法在它们中,我只需要调用类的函数声明。
您应该将它们作为参数传递给函数调用
difference = out2.sub(x, y);
在.h文件中,您应该使用参数来定义它们
class subtraction
{
public:
int sub(int x, int y);
};
功能过载