need help with array, reverse string, and switch please help.

please help, my hw is due tomorrow and i'm somewhat of a noob in my c++ class which is due tomorrow. I'm understand the language somewhat but i'm having trouble putting the pieces together, specifically transposing array and reversing the string.

Below is my hw and my code that i have written so far. i got stuck at writing the transposing portion, and i keep getting an error in my reverse string. can someone please take a look and critique me please. or show me what i did wrong.

Write a C++ program that prompts the user with the following options:
Matrix String Quit

(1) If the user selects “M” or “m” then call a user-defined function called float average (void) that will the following:
a. Prompt the user to enter three sets of three numbers (type float) and store the numbers in a 3 x 3 array.
b. Find the transpose of the matrix and print the results in this function.
c. Find the sum of the original matrix and transposed matrix and print the original, transpose, and the sum matrices in this function. Note the output should be in three rows and three columns format with space in between each column as follows:
1 2 3
2 0 9
12 3 7

(2) 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.


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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  #include <iostream>
#include <string>
using namespace std;

float Average();
void rev_string(void);
void Reverse(char name[]);

int main()
{

	char selection;
	char ch;
	do
	{
		cout << " Please select one of the follow pattern" << endl;
		cout << "Matrix    String    Quit " << endl;
		cout << "Please enter the M, S or Q" << endl;
		cin >> selection;
		switch (selection)
		{
		case 'm':
		case 'M':
			float Average();
			break;
		case 'S':
		case 's':
			rev_string();
			break;
		case 'Q':
		case 'q':
			return 0;
		default:
			cout << "This selection is invalid, please insert a valid selection:" << endl;
			break;
		}
		cout << "Please enter Q to quit" << endl;
		cin >> ch;
	} while (ch != 'Q' && ch != 'q' && ch != 'P' && ch != 'C');//q or Q to quit, 

	system("pause");
	return 0;
}

float Average() // case M
{
	float input[3][3]; // 3x3 array
	float inputT[3][3];//transposed 3x3 array

	cout << "Please enter 3 sets of numbers" << endl; //asking input from user
	for (int row = 0; row < 3; row++)
	{
		for (int column = 0; column < 3; column++)
		{
			cin >> input[row][column];
		}

		cout << '\n';
	}


	//displaying user input
	for (int row = 0; row < 3; row++)
	{
		for (int column = 0; column, 3; column++)
		{
			cout << input[row][column] << " ";
		}
		cout << endl;
	}
	cout << endl;

	// user input as a transposed array
	for (int row = 0; row < 3; row++)
	{
		for (int column = 0; column < 3; column++)
		{
			input[row][column] = input[column][row];
			cout << input[row][column] << " ";
		}
		cout << endl;
	}

	// sum of arrays
	float addinput[3][3];
	for (int row = 0; row < 3; row++)
	{

	}
}

void rev_string(char name[])
{
	// declare variable
	char name[100];

	// get user data
	cout << "Enter a string you want to reverse: ";
	cin.getline(name, sizeof(name));

	cout << "The orignal string was: " << name; //displaying original string
	cout << "\nYour name reversed is: ";//reversed string


	Reverse(name);// function declaration
	cout << endl;

}
void Reverse(char name[])
{
	if (*name == '\0')
	{
		return;
	}
	else // the recursive
	{
		Reverse(name + 1);
		cout << *(name);
	}
}
Topic archived. No new replies allowed.