Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Help Needed! I need to make a string calculator using operator overloading.

ID: 3684124 • Letter: C

Question

C++ Help Needed!

I need to make a string calculator using operator overloading. It needs to take two user input strings and add and subtract them (not concatenation). So, it needs to add or subtract the ASCII values of each character of the string inputs.

For Addition: If the addition of two values exceeds the ascii value of 'z' which is 122, 'z' needs to be subtracted from it. So, a+c is 97+99 = 196. So, that value needs to be subtracted by 'z' so that it becomes 196-122 = 74. Which means a+c = J.

For Subtraction: If the subtraction of two values is below the ascii value of 'A' which is 65, 'A' needs to be added to it. So, e-d is 101+100 = 1. So, that value needs to be added by 'A' so that it becomes 1+65 = 66. Which means e - d = B.

Also, 'space' should be read as having a value of 0. Not 32 like it is in the ASCII table.

Here is an ASCII table for reference: http://www.asciitable.com/

Sample Input and Output:

Thank you!

Explanation / Answer

#include<iostream.h>

#include<conio.h>

class complex

{

char a[10], char b[10];

int an[10] ,b[10];

int result[i];

char result1[i];

public:

void getvalue()

{

cout<<"Enter the a ten letter word a";

for (i=1,i<=10,i++)

cin>>a[i];

cout<<"Enter the a ten letter word b";

for (i=1,i<=10,i++)

cin>>b[i];

}

complex operator plus(char as[i], bs[i])

{

for (i=1; i<10; i++)

{

an[i] = as[i];

bn[i] = bs[i];

result[i] = an[i] + bn[i];

if result > 127

{

an[i] = result – 127

result1[i] = an[i]

}

else reult1[i] = result[i];

cout>> result is <<result1[i]

}

}

complex operator minus(char as[i], bs[i])

{

for (i=1; i<10; i++)

{

an[i] = as[i];

bn[i] = bs[i];

result[i] = an[i] - bn[i];

if result [i]< 65

{

an[i] = result + 65

result1[i] = an[i]

}

else reult1[i] = result[i];

cout>> result is <<result1[i]

}

}

void main()

{

clrscr();

complex obj1,obj2,result,result1;

obj1.getvalue();

obj2.getvalue();

int op;

cout << “enter the option “;

switch (op){

case 1:

complex operator plus(char a[i], b[i])

case 2:

complex operator minus(char a[i], b[i])

}

getch();

}