Now, please give a teacher asked a question in class, he Chen students will give answer,
Implementation framework based on the following base class please
The class Group
{
Public:
Virtual int the add (int x, int y)=0.//output the result of addition
Virtual int sub (int x, int y)=0;//the output result of subtraction
}
Build GroupA, GroupB and GroupC sent three categories:
And write the main function, the main function of a base class Group pointer array, unified by the array element to add and sub operations,
Input format:
First enter an integer n, this is the number of classes, no more than 20,
Then enter n number (values are 1, 2, or 3), it is each students belong to categories, the first number is the first student category, followed by two student category,... And, finally, n student category, category to 1, show that the student is the first class A; For 2, suggests that the student is class B, 3 shows that when is class C,
Next each line to enter a math problem, mathematical problem consists of two parts, the first part of the serial number of student questioning, it is a no more than the positive integer n, 1 is the first student, 2 said the second student, n n student; The second part is concrete problem, the likelihood is addition, may also be a subtraction, note: there is no space between the operand and add and subtract Numbers, both operands of the nonnegative integers is less than 999, subtraction, the minuend is not less than the reduction,
If a line begins with 0, explain questions over,
The output format:
Output for a given students questions,
Input the sample:
4
1 2 3 3
1 79 + 81
2, 81-79
4 183 + 69
0
The output sample:
160
12
142
CodePudding user response:
https://paste.ubuntu.com/p/ZHByfFgNhj/codeCodePudding user response:
#includeusing namespace std;
The class Group {
Public:
Virtual int the add (int x, int y)=0.
Virtual int sub (int x, int y)=0;
};
The class GroupA: public Group {
Public:
GroupA (int x=0, int y=0) : a (x), b (y) {}
Int the add (int x, int y) {
Cout
}
Int sub (int x, int y) {
Cout
Private:
int a;
Int b;
};
The class GroupB: public Group {
Public:
GroupB (int x=0, int y=0) : a (x), b (y) {}
Int the add (int x, int y) {
Cout
}
Int sub (int x, int y) {
Int b, a, c, d;
B=x - 10 * (x/10);
A=y - 10 * (y/10);
C=x - 10 * (x/100);
D=y - 10 * (y/100);
If (b{if (x % 100 & gt; 0 & amp; & Y %==0 100 & amp; & Y % 10 & gt; 0) cout
Private:
int a;
Int b;
};
The class GroupC: public Group {
Public:
GroupC (int x=0, int y=0) : a (x), b (y) {}
Int the add (int x, int y) {
Int b, a, c, d;
B=x - 10 * (x/10);
A=y - 10 * (y/10);
C=x - 10 * (x/100);
D=y - 10 * (y/100);
If (b{if (x % 100 & gt; 0 & amp; & Y %==0 100 & amp; & Y % 10 & gt; 0) cout
Int sub (int x, int y) {
Int b, a, c, d;
B=x - 10 * (x/10);
A=y - 10 * (y/10);
C=x - 10 * (x/100);
D=y - 10 * (y/100);
If (b{if (x % 100 & gt; 0 & amp; & Y %==0 100 & amp; & Y % 10 & gt; 0) cout
Private:
int a;
Int b;
};
Int main () {
int n;
cin> n;
int i;
Group * p [4];
GroupA m;
P [1]=& amp; m;
GroupB j;
P [2]=& amp; j;
GroupC o;
P [3]=& amp; o;
Char g [89];
Int a, [99].//serial number
Int d [99];//number
Int b [99];
Int c [99];
For (I=1; i>=n; I++) {
cin> D [I];
}
for(i=1; ; I++) {
cin> A [I] & gt;> [I] b & gt;> [I] g & gt;> C [I];
If (a [I]==0) break;
}
For (int k=a [I], I=1; ; I++) {
K=a, [I].
If (d [k]==1) {
M=GroupA (b [k], c [k]);
If (g [k]=='43')
{p [1] - & gt; Add (b [k], c [k]); }
The else p [1] - & gt; Sub (b [k], c [k]); }
Else if (d [k]==2) {
J=GroupB (b [k], c [k]);
If (g [k]=='43')
{p [2] - & gt; Add (b [k], c [k]); }
The else p [2] - & gt; Sub (b [k], c [k]); }
Else if (d (k)==3) {
O=GroupC (b [k], c [k]);
If (g [k]=='43')
{p [3] - & gt; Add (b [k], c [k]); }
The else p [3] - & gt; Sub (b [k], c [k]); }
return 0;
}
CodePudding user response:
Emmmm...Put down my code
# include & lt; Iostream>
#include
#include
#include
#include
#include
#include
using namespace std;
The class Group
{
Public:
Virtual int the add (int x, int y)=0.//output the result of addition
Virtual int sub (int x, int y)=0;//the output result of subtraction
};
The class GroupA: public Group
{
Public:
Int the add (int x, int y) {
Return x + y;
}
Int sub (int x, int y) {
Return the x - y;
}
};
The class GroupB: public Group
{
Public:
Int the add (int x, int y) {
Return x + y;
}
Int sub (int x, int y) {
Int num1 [4]={0};
Int num2 [4]={0};
Int I=0, j=0;
Do {
Num1 [i++]=x % 10;
Num2 [j++]=y % 10;
X/=10;
Y/=10;
} while (x | | y); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull