inputing char? functional decomposition

Really confused with functional decomposition. Can't seem to find in book by that name:


use functional decomposition approach.
You should have a function to read the character to use, so its prototype can be
something like this.
char readChar();
Another function to read the value for the row and also for the columns. That is,
the same function is called twice to read these two different values. Its
prototype can be something like this:
int getNum();
Lastly a function to print the box, and its prototype can be something
like this:
void printBox(int rows,int cols,char ch);
You should still have the same output as before, hence a sample run is as
follows.
Enter character to use : @
How many rows? : 6
How many columns? : 4
@@@@
@@@@
@@@@
@@@@
@@@@
@@@@
Allow private messages from your account settings!
I have the same question and its my first time in college. I have the exact same problem i was wondering can anyone help?
this is what i have so far but im kinda lost


#include <iostream>
#define ROW 6
#define COL 4
using namespace std;
char readChar();
int getNum();
void printBox(int rows, int cols, char ch);

int main()
{
char ch;
int rows = 6;
int cols = 4;

cout << "Enter the character to be use: "; //display character
cin >> ch;

}
int getNum()
{

int rows;
int cols;
cout << "Enter the number of rows in the matrix \n"; // displat rows
cin >> rows;
cout << "Enter the number of columns in the matrix \n"; //display column
cin >> cols;

cout << endl;
system("pause");
return 0;
}

void printBox(int rows, int cols, char ch);

for (rows = 0; rows < ROW; rows++) // this display rows number
else (cols = 0; cols < COL; cols++) // this display columns number

cout << "@"; // this display character
cout << endl;

cout << endl << endl;


I think that this is similar:
ask what you don't understand;

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
//printChar.cpp
//Add description.

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

char readChar();
int setNum();
void printBox(int row,int col,char item);

int main(){

int row;
int col;
char mychar;

row=setNum();
col=setNum();
mychar=readChar();

printBox(row,col,mychar);

return 0; //indicates success
}//end main

char readChar(){

char myChar;
	cout<<"Enter a char: ";
	cin>>myChar;

return myChar;
}//end function readChar

int setNum(){

int num;
	cout<<"Enter a num: ";
	cin>>num;

return num;	
};//end function setNum

void printBox(int r,int c,char item){
	for(int row=0;row<r;row++){
		for(int col=0;col<c;col++){
			cout<<item<<' ';
		}//end inner for
	cout<<endl; //ouput a new line
	}//end outer for
}//end function printBox 



Eyenrique-MacBook-Pro:Study Eyenrique$ ./printChar 
Enter a num: 3
Enter a num: 3
Enter a char: @
@ @ @ 
@ @ @ 
@ @ @ 
Eyenrique-MacBook-Pro:Study Eyenrique$ ./printChar 
Enter a num: 3
Enter a num: 4
Enter a char: #
# # # # 
# # # # 
# # # # 
im new to america and this language is new. when i didnt have my void and and int get num, it ran perfect, showing @@ but i confuse adding char readChar and more
return type-> char readChar();
name function-> readChar

this means that your function will return some char variable.
when is void as in -> void printBox(parameter,parameter,parameter);
your function will not return any variable;

makes sense this for you?

by the way, where are you from?
Last edited on
How do you ask the user to enter row and column? Output supposed to look like this:

Enter character to use : @
How many rows? : 6
How many columns? : 4
@@@@
@@@@
@@@@
@@@@
@@@@
@@@@

The 6 and 4 are just example input from the user. So if the user inputs 5 for rows and 10 for columns, it can also do 5 rows of any symbol and 4 columns.
Well, just add some statements:

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
//printChar.cpp
//Add description.

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

char readChar();
int setNum();
void printBox(int row,int col,char item);

int main(){

int row;
int col;
char mychar;

cout<<"\nWe need a value for rows\n";
row=setNum();
cout<<"\nNow a value for columns\n";
col=setNum();
mychar=readChar();

printBox(row,col,mychar);

return 0; //indicates success
}//end main

char readChar(){

char myChar;
	cout<<"Enter a char: ";
	cin>>myChar;

return myChar;
}//end function readChar

int setNum(){

int num;
	cout<<"Enter a num: ";
	cin>>num;

return num;	
};//end function setNum

void printBox(int r,int c,char item){
	for(int row=0;row<r;row++){
		for(int col=0;col<c;col++){
			cout<<item<<' ';
		}//end inner for
	cout<<endl; //ouput a new line
	}//end outer for
}//end function printBox 



We need a value for rows
Enter a num: 3

Now a value for columns
Enter a num: 3
Enter a char: @
@ @ @ 
@ @ @ 
@ @ @ 
Topic archived. No new replies allowed.