There's something I just have to hate. Void does not need to be used in argument lists in C++. It just tends to look ugly. Knowing that I have to use "..." to create variables argument lists, I really think void can be left out.
Printable View
Are there any suggestions as to how I could write the function(s) that draw the figures? I've fixed all the formatting stuff you guys didn't like, but that doesn't help the problem.
I gave all the information I was given for the assignment. I know several classmates have finished, and may end up asking them for help. This is the only assignment so far that has stumped me so much. What really bugs me is that a professor who has used my book for years at Hawaii posted his concept of the answers online to all of them BUT this one. I wish he had posted this one so that I could figure out how it works.
I still think you should go with the seven segment display:
The size of the box tells you where each of the segments goes (see above for 7x7); the digit tells you which segments you need to draw and which ones you don't. (You could either do switches, or a lookup table, or a whole heck of a lot of if statements, or probably some other things I'm not thinking of right now to decide which segments are on, based on the digit.)Code:*******
* *
* *
*******
* *
* *
*******
I think I have what I need to do. It will just be a whole freaking bunch of if and for statements. I will post it when I am done so you can see what I ended up doing. It will be a total pain in the ass, and a really long piece of code to do such a trivial task, but it will give me some points.
Thanks
So how would that work in a 5X5 or 6X5 grid? Surely there is a minimum grid and even perhaps a maximum grid.
A grid of 1 or 2 is impossible. A grid of 3 is only good for a single character, so also no good.
It's not until you get a grid of 7X7 that a 5X5 digit will fit, which is probably the first one where all digits could be recognized, and that's with no space between it and the grid.
... thinking... drawing....
Hold the phone - I've figured this out.
If you map a 5X5 character, you can then apply enough rules to scale them all. Look at this picture of 3. The (complicated) rules would apply to all numbers. Basically, it works with the concept of filler positions. Row1, 3 and 5 need to be respected, and col1, col3 and col5 need to be respected. Everything else can be repeated. It should work for all digits. You get to define them and structure the program to do the rest. :)
And, the code to get you started... (you're welcome)
Code:#include <stdio.h>
void print_digit(char c[5][5], int newgrid_dim ) ;
int main(void) {
char grid3[5][5] = { // the character "3"
{ '*','*', '*','*', '*' } ,
{ ' ',' ', ' ',' ', '*' } ,
{ '*','*', '*','*', '*' } ,
{ ' ',' ', ' ',' ', '*' } ,
{ '*','*', '*','*', '*' } } ;
int newgrid_dim = 9 ;
int newgrid_center = (newgrid_dim+1) / 2 ;
int i , j ; // dimension of new grid (row, col)
int a , b ; // dimension of grid3
// char * gridptr ;
// gridptr = grid3 ;
print_digit(grid3, 9) ;
}
void print_digit(char grid[5][5] , int newgrid_dim) {
int newgrid_center = (newgrid_dim+1) / 2 ;
int i , j ; // dimension of new grid (row, col)
int a , b ; // dimension of grid3
for (i = 1 ; i <= newgrid_dim ; ++i ) {
for (j = 1 ; j <= newgrid_dim ; ++j ) {
if (i==1) a = 1 ;
else if (i < newgrid_center) a = 2 ; // filler position
else if (i == newgrid_center) a = 3 ;
else if (i < newgrid_dim) a = 4 ; // filler position
else a = 5 ;
if (j==1) b = 1 ;
else if (j < newgrid_center) b = 2 ; // filler position
else if (j == newgrid_center) b = 3 ;
else if (j < newgrid_dim) b = 4 ; // filler position
else b = 5 ;
// a & b are now set to point to the proper character to write
// at i,j
printf("%c", grid[a-1][b-1] ) ;
}
printf("\n") ;
}
}
You should know that everything inside a function should be indented. It makes it confusing otherwise...Code:#include <stdio.h>
void print_digit(char c[5][5], int newgrid_dim ) ;
int main(void) {
char grid3[5][5] = { // the character "3"
{ '*','*', '*','*', '*' } ,
{ ' ',' ', ' ',' ', '*' } ,
{ '*','*', '*','*', '*' } ,
{ ' ',' ', ' ',' ', '*' } ,
{ '*','*', '*','*', '*' } } ;
int newgrid_dim = 9 ;
int newgrid_center = (newgrid_dim+1) / 2 ;
int i , j ; // dimension of new grid (row, col)
int a , b ; // dimension of grid3
// char * gridptr ;
// gridptr = grid3 ;
print_digit(grid3, 9) ;
}
void print_digit(char grid[5][5] , int newgrid_dim) {
int newgrid_center = (newgrid_dim+1) / 2 ;
int i , j ; // dimension of new grid (row, col)
int a , b ; // dimension of grid3
for (i = 1 ; i <= newgrid_dim ; ++i ) {
for (j = 1 ; j <= newgrid_dim ; ++j ) {
if (i==1) a = 1 ;
else if (i < newgrid_center) a = 2 ; // filler position
else if (i == newgrid_center) a = 3 ;
else if (i < newgrid_dim) a = 4 ; // filler position
else a = 5 ;
if (j==1) b = 1 ;
else if (j < newgrid_center) b = 2 ; // filler position
else if (j == newgrid_center) b = 3 ;
else if (j < newgrid_dim) b = 4 ; // filler position
else b = 5 ;
// a & b are now set to point to the proper character to write
// at i,j
printf("%c", grid[a-1][b-1] ) ;
}
printf("\n") ;
}
}
Yes, I missed that one. No comments about the cleverness of the algorithm??
I'm not one for algorithms :p
Difficult to understand most of the times...
No void in C meant variable arguments. Void in C++ is not necessary, but may be added to explicitly declare there should be no variable argument list, in response to mats's reply.
empty parameter list in C means variable arguments.
That's why void as a parameter list in C is required to specify the function with no arguments.
empty parameter list in C++ means no arguments, that's why void in parameters list is fully equivalent to empty parameters list and could be fully avoided in C++.
It is used only to make code in headers look like the C-code
OP:
There is a world of difference in what she's saying and what is true. Actually, in C, empty parens is an undefined argument list in the sense that you can pass anything and the compiler ignores that. Variable argument lists can be passed "anything" too, but the arguments during he call are contained in a va_list. The prototypes for these functions is obvious. That allows you to take some advantage of the arguments you pass. Using an undefined argument list you can't make an assumption what arguments are named or their types, and there is nothing like va_list to maintain them.
In C++, empty parens is an empty argument list, but only because Stroustrup designed things this way. Ugly or not, void will still be necessary in code that "crosses the aisle" to C.
Yeah what citizen was saying is what I was getting at -- an empty argument list does not necessarily denote a variable argument list.