|
Ok this is a study program because we will have a similiar program like this on the test. Now I figured out the matrix part of the program and the quit, but not the string. All I need is the STRING part to finish this program so that I can study it. Can any one do that part for me because Im confused on the String part. There is the study question below.
C++ Study Question:
Matrix String Quit
• If the user selects “M” or “m” then call a user-defined function called double average (void) that will the following:
a. Prompt the user to enter three sets of five numbers (type float) and store the numbers in a 3 x 3 array.
b. Determine the largest value of 9 values and print it in the main function.
c. Determine the transpose of the original matrix and then find the sum of the original and transpose matrices and print the result in this function.
• If the user selects “S” or “s” then call a user-defined function void rev_str (void) that
a. Prompts the user to enter a string and store it into one-dimensional array.
b. Replace the content of the string with the string reversed and save into another array.
c. Print both the original string and reversed one in this function.
• If the user enters “Q” or “q” then you should terminate the program. If the user enters any other selection it should prompts the user invalid selection and try again.
Do not use any global arrays or variables.
|
|
|
Show Us What You Have Done Till Now...No One Is gonna Write Full Code For You....Post A Part Of Code Where You Are Stuck...Someone In This Forum Will Definetly Help You
|
|
|
Here is the whole code. I got 2 errors and Ive been stuck on it for days. Need help in figuring this out. Here are the 2 errors: Also I indentified the error by commenting Error next to a statement.
1.
62) : error C2111: pointer addition requires integral operand
2.)62) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
>#include<iostream.h>
>
>
>void rev_str(void);
>void reverse (char *, char *);
>void doubleAverage ();
>
>
>float main()
>
>{
>
> char input;
> cin>>input;
> while (input != 'q')
> {
> cout<<"Matrix String Quit"<<endl;
> //cin>>input;
>
> switch(input)
> {
> case 'S':
> case 's':
> rev_str();
> break;
>
> case 'Q':
> case 'q':
> cout<<"This program has ended."<<endl;
> break;
>
> default:
> cout<<"Try reentering another input."<<endl;
> input = 'z';
> break;
> }
>
> }
>
>return (0);
>}
>
> void rev_str()
> {
> const int x=30;
> char Input_String[x];
> char Output_String[x];
>
>
>
> cout<<"Please enter a string:\n";
> cin.get();
> cin.getline(Input_String, x);
> reverse(Input_String, Output_String);
> cout<<"The Original string is "<<Input_String<<endl;
> cout<<"The reversed string is "<<Output_String<<endl<<endl;
> }
>
> void reverse(char *in_str, char *out_str)
> {
> float y=0;
> while (*(in_str + y) != '\0')//Error
> {
> y++;
> }
> for(y--; y>=0; y--)
> {
> *out_str++ = *(in_str + y);
> }
> *out_str = '\0';
> }
>
>
>
> void doubleAverage()
>
> {
>
> float result=0;
>
>
>
> {
> float num 8;
> float x;
>
> cout << "Please enter the first set of three number:" << endl;
> cin >> num0 >> num1 >> num2;
>
> cout << "Please enter second set of three numbers:" << endl;
> cin >> num3 >> num4 >> num5;
>
> cout << "Please enter third set of three numbers:" << endl;
> cin >> num6 >> num7 >> num8;
>
>
> for (int i =0; i <9; i++)
> t number.
> {
> if (x < numi)
> x + numi;
> }
>
> cout << "The greatest number of the three groups is "<<x<< "."
><<endl;
>
> float sum=0;
>
> for (int j=0; j<9; j++)
>
> {
> sum = sum + numj;
> }
>
> cout << "The sum of the numbers is " << sum << "." << endl;
>
> float temp;
> int counter, index;
>
> for (counter = 0; counter < 8; counter++)
> {
> for (index=0; index < 8 - counter; index++)
> if(numindex > numindex + 1)
> {
> temp = numindex;
> numindex = numindex + 1;
> numindex + 1 = temp;
> }
> for (int a =0; a < 9; a++)
> rt.
> {
> cout << numa << "";
> }
> }
>
>
>
>
|
|
|
Here is the program again for anyone using a compiler. Sorry for the greater than/less than signs
#include<iostream.h>
void rev_str(void);
void reverse (char *, char *);
void doubleAverage ();
float main()
{
char input;
cin>>input;
while (input != 'q')
{
cout<<"Matrix String Quit"<<endl;
//cin>>input;
switch(input)
{
case 'S':
case 's':
rev_str();
break;
case 'Q':
case 'q':
cout<<"This program has ended."<<endl;
break;
default:
cout<<"Try reentering another input."<<endl;
input = 'z';
break;
}
}
return (0);
}
void rev_str()
{
const int x=30;
char Input_String[x];
char Output_String[x];
cout<<"Please enter a string:\n";
cin.get();
cin.getline(Input_String, x);
reverse(Input_String, Output_String);
cout<<"The Original string is "<<Input_String<<endl;
cout<<"The reversed string is "<<Output_String<<endl<<endl;
}
void reverse(char *in_str, char *out_str)
{
float y=0;
while (*(in_str + y) != '\0')//Errror
{
y++;
}
for(y--; y>=0; y--)
{
*out_str++ = *(in_str + y);
*out_str = '\0';
}
void doubleAverage()
{
float result=0;
{
float num 8;
float x;
cout << "Please enter the first set of three number:" << endl;
cin >> num0 >> num1 >> num2;
cout << "Please enter second set of three numbers:" << endl;
cin >> num3 >> num4 >> num5;
cout << "Please enter third set of three numbers:" << endl;
cin >> num6 >> num7 >> num8;
for (int i =0; i <9; i++)
t number.
{
if (x < numi)
x + numi;
}
cout << "The greatest number of the three groups is "<<x<< "."
<<endl;
float sum=0;
for (int j=0; j<9; j++)
{
sum = sum + numj;
}
cout << "The sum of the numbers is " << sum << "." << endl;
float temp;
int counter, index;
for (counter = 0; counter < 8; counter++)
{
for (index=0; index < 8 - counter; index++)
if(numindex > numindex + 1)
{
temp = numindex;
numindex = numindex + 1;
numindex + 1 = temp;
}
for (int a =0; a < 9; a++)
rt.
{
cout << numa << "";
}
}
|
|
|
Your code is really messy...the errors which u said...i have removed them but it contains alot of other errors.....like undeclared variable.....you need to study your books again.....i could have corrected your code fully....but you try first.....
here is the code with removal of 2 errors which you were mentioning
#include<iostream.h>
void rev_str(void);
void reverse (char *, char *);
void doubleAverage ();
float main()
{
char input;
cin>>input;
while (input != 'q')
{
cout<<"Matrix String Quit"<<endl;
//cin>>input;
switch(input)
{
case 'S':
case 's':
rev_str();
break;
case 'Q':
case 'q':
cout<<"This program has ended."<<endl;
break;
default:
cout<<"Try reentering another input."<<endl;
input = 'z';
break;
}
}
return (0);
}
void rev_str()
{
const int x=30;
char Input_String[x];
char Output_String[x];
cout<<"Please enter a string:\n";
cin.get();
cin.getline(Input_String, x);
reverse(Input_String, Output_String);
cout<<"The Original string is "<<Input_String<<endl;
cout<<"The reversed string is "<<Output_String<<endl<<endl;
}
void reverse(char *in_str, char *out_str)
{
int y=0;//changed it to int from float
while (*(in_str + y) != '\0')//Errror
{
y++;
}
for(y--; y>=0; y--)
{
*out_str++ = *(in_str + y);
*out_str = '\0';
}
}//This Was Missing
void doubleAverage()
{
float result=0;
{
float num 8;
float x;
cout << "Please enter the first set of three number:" << endl;
cin >> num0 >> num1 >> num2;
cout << "Please enter second set of three numbers:" << endl;
cin >> num3 >> num4 >> num5;
cout << "Please enter third set of three numbers:" << endl;
cin >> num6 >> num7 >> num8;
for (int i =0; i <9; i++)
t number.
{
if (x < numi)
x + numi;
}
cout << "The greatest number of the three groups is "<<x<< "."
<<endl;
float sum=0;
for (int j=0; j<9; j++)
{
sum = sum + numj;
}
cout << "The sum of the numbers is " << sum << "." << endl;
float temp;
int counter, index;
for (counter = 0; counter < 8; counter++)
{
for (index=0; index < 8 - counter; index++)
if(numindex > numindex + 1)
{
temp = numindex;
numindex = numindex + 1;
numindex + 1 = temp;
}
for (int a =0; a < 9; a++)
rt.
{
cout << numa << "";
}
}
|
|
|
|
|
|
|
// |