944,103 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2119
  • C++ RSS
Mar 10th, 2005
0

problem printing output

Expand Post »
Iam reading in a 4row 3column table.
Iam refering to char_function[4][3] in the following code.This is a part of a larger program. You can neglect all other things and look at char_function
my aim is to print it out
C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. using namespace std;
  3. int N, Q, M;//number of user inputs, states, and outputs of the machine
  4. char char_table[4][3] = { {0,0,0},
  5. {0,1,0},
  6. {1,0,0},
  7. {1,1,0} };
  8.  
  9. char ex_table[4][4] = { {0,0,0,0},
  10. {0,1,0,0},
  11. {1,0,0,0},
  12. {1,1,0,0} };
  13.  
  14. void char_func();
  15. void ex_func();
  16. int power(int n);
  17. //------------------------------------------------------
  18. int main(){
  19. int itr;
  20. cout<<" Enter 1)The number of inputs\n\t2)Number of states ,and";
  21. cout<<"\n\t3)Number of outputs \n of the sequential state machine \n";
  22. cin>> N ; cin>> Q ; cin>> M ;
  23. cout<<N ; cout<<Q ; cout<<M ;
  24. char_func();
  25. ex_func();
  26. return 1;
  27. }
  28. //int CHARSSM[power(Q)-1][2*(N+M)-1];
  29.  
  30. void char_func(){
  31. int itr,itr1,itr2;
  32. char dummy;
  33. int count=0;
  34. cout<<"\n please write out the chrecteristic table of your flip-flop on a piece of paper";
  35. cout<<"\n Iam assuming FF with 2 inputs and 2 states \n"; //I don't know if can be of different types too.
  36. cout<<"\n The first two columns have been filled by the program ";
  37. cout<<"in the order corresponding to q=0,q=1,q=2 and q=3 \n";
  38. cout<<" Enter the third column of the CHARECTERISTIC table \n";
  39. cout<<" Enter M for the memory state and T for toggle state\n";
  40. cout<<" The order in which you enter the values is important\n";
  41.  
  42. for(itr = 0; itr < 4; itr++ ){cin>> dummy; char_table[itr][2] = dummy;}
  43.  
  44. for(itr1 = 0; itr1 < 4; itr1++ ){cout<<"\n";
  45. for(itr = 0; itr < 3 ; itr++ ){count++;
  46. cout<<" "<< char_table[itr1][itr];
  47. }
  48. }
  49. cout<<"count = " << count;
  50. cout<<"\n\n";
  51. cout<< char_table[0][0] << char_table[1][0]<< char_table[2][0]<< char_table[3][0];
  52. cout<< char_table[0][1] << char_table[1][1]<< char_table[2][1]<< char_table[3][1];
  53. }
  54. //----------------------------------------------------------------------------------
  55. void ex_func(){
  56.  
  57.  
  58. }


why is the output showing only the last column of the table??

puzzeled,
arjun
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
arikeri is offline Offline
25 posts
since Mar 2005
Mar 10th, 2005
0

Re: problem printing output

You may want to make your tables -- and dummy input --have int type. A character 0 ('\0') is not the same as '0'. Either that, or use '0' and '1' in the char table.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Mar 10th, 2005
0

Re: problem printing output

Quote originally posted by Dave Sinkula ...
You may want to make your tables -- and dummy input --have int type. A character 0 ('\0') is not the same as '0'.
Actually the reason I used 'char' type is because I need to pass this to an already function which takes inout of char type

Quote ...
Either that, or use '0' and '1' in the char table.
This isn't helping me either . The function ain't compiling??
Last edited by Dave Sinkula; Mar 10th, 2005 at 1:38 pm. Reason: fixed QUOTE tag
Reputation Points: 10
Solved Threads: 0
Light Poster
arikeri is offline Offline
25 posts
since Mar 2005
Mar 10th, 2005
0

Re: problem printing output

Quote originally posted by arikeri ...
This isn't helping me either . The function ain't compiling??
I can't see what you're doing. Here's what I had done.
#include<iostream>
using namespace std;
int N, Q, M;//number of user inputs, states, and outputs of the machine
char char_table[4][3] = { {'0','0','0'},
                          {'0','1','0'},
                          {'1','0','0'},
                          {'1','1','0'} };

char ex_table[4][4] = {   {'0','0','0','0'},
                          {'0','1','0','0'},
                          {'1','0','0','0'},
                          {'1','1','0','0'} };

void char_func();
void ex_func();
int  power(int n);
//------------------------------------------------------
int main(){
int itr;
    cout<<" Enter  1)The number of inputs\n\t2)Number of states ,and";
    cout<<"\n\t3)Number of outputs \n of the sequential state machine \n";
    cin>> N ;  cin>> Q ;  cin>> M ;
    cout<<N ;  cout<<Q ;  cout<<M ;
    char_func();
    ex_func();
return 1;
}
//int CHARSSM[power(Q)-1][2*(N+M)-1];

void char_func(){
int itr,itr1,itr2;
char dummy;
int count=0;
    cout<<"\n please write out the chrecteristic table of your flip-flop on a piece of paper";
    cout<<"\n Iam assuming FF with 2 inputs and 2 states \n"; //I don't know if can be of different types too.
    cout<<"\n The first two columns have been filled by the program ";
    cout<<"in the order corresponding to q=0,q=1,q=2 and q=3 \n";
    cout<<" Enter the third column of the CHARECTERISTIC table \n";
    cout<<" Enter M for the memory state and T for toggle state\n";
    cout<<" The order in which you enter the values is important\n";

    for(itr = 0; itr < 4; itr++ ){cin>> dummy; char_table[itr][2] = dummy;}

    for(itr1 = 0; itr1 < 4; itr1++ ){cout<<"\n";
       for(itr = 0; itr < 3 ; itr++ ){count++;
           cout<<" "<< char_table[itr1][itr];
       }
    }
    cout<<"count = " << count;
    cout<<"\n\n";
    cout<< char_table[0][0] << char_table[1][0]<< char_table[2][0]<< char_table[3][0];
    cout<< char_table[0][1] << char_table[1][1]<< char_table[2][1]<< char_table[3][1];
}
//----------------------------------------------------------------------------------
void ex_func(){


}
A sample run is then as follows.
/* my output
 Enter  1)The number of inputs
	2)Number of states ,and
	3)Number of outputs 
 of the sequential state machine 
1 0 1
101
 please write out the chrecteristic table of your flip-flop on a piece of paper
 Iam assuming FF with 2 inputs and 2 states 

 The first two columns have been filled by the program in the order corresponding to q=0,q=1,q=2 and q=3 
 Enter the third column of the CHARECTERISTIC table 
 Enter M for the memory state and T for toggle state
 The order in which you enter the values is important
1 0 1 1

 0 0 1
 0 1 0
 1 0 1
 1 1 1count = 12

00110101
*/
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Mar 10th, 2005
0

Re: problem printing output

Quote originally posted by Dave Sinkula ...
I can't see what you're doing. Here's what I had done.
#include<iostream>
using namespace std;
int N, Q, M;//number of user inputs, states, and outputs of the machine
char char_table[4][3] = { {'0','0','0'},
                          {'0','1','0'},
                          {'1','0','0'},
                          {'1','1','0'} };

char ex_table[4][4] = {   {'0','0','0','0'},
                          {'0','1','0','0'},
                          {'1','0','0','0'},
                          {'1','1','0','0'} };

void char_func();
void ex_func();
int  power(int n);
//------------------------------------------------------
int main(){
int itr;
    cout<<" Enter  1)The number of inputs\n\t2)Number of states ,and";
    cout<<"\n\t3)Number of outputs \n of the sequential state machine \n";
    cin>> N ;  cin>> Q ;  cin>> M ;
    cout<<N ;  cout<<Q ;  cout<<M ;
    char_func();
    ex_func();
return 1;
}
//int CHARSSM[power(Q)-1][2*(N+M)-1];

void char_func(){
int itr,itr1,itr2;
char dummy;
int count=0;
    cout<<"\n please write out the chrecteristic table of your flip-flop on a piece of paper";
    cout<<"\n Iam assuming FF with 2 inputs and 2 states \n"; //I don't know if can be of different types too.
    cout<<"\n The first two columns have been filled by the program ";
    cout<<"in the order corresponding to q=0,q=1,q=2 and q=3 \n";
    cout<<" Enter the third column of the CHARECTERISTIC table \n";
    cout<<" Enter M for the memory state and T for toggle state\n";
    cout<<" The order in which you enter the values is important\n";

    for(itr = 0; itr < 4; itr++ ){cin>> dummy; char_table[itr][2] = dummy;}

    for(itr1 = 0; itr1 < 4; itr1++ ){cout<<"\n";
       for(itr = 0; itr < 3 ; itr++ ){count++;
           cout<<" "<< char_table[itr1][itr];
       }
    }
    cout<<"count = " << count;
    cout<<"\n\n";
    cout<< char_table[0][0] << char_table[1][0]<< char_table[2][0]<< char_table[3][0];
    cout<< char_table[0][1] << char_table[1][1]<< char_table[2][1]<< char_table[3][1];
}
//----------------------------------------------------------------------------------
void ex_func(){


}
A sample run is then as follows.
/* my output
 Enter  1)The number of inputs
	2)Number of states ,and
	3)Number of outputs 
 of the sequential state machine 
1 0 1
101
 please write out the chrecteristic table of your flip-flop on a piece of paper
 Iam assuming FF with 2 inputs and 2 states 

 The first two columns have been filled by the program in the order corresponding to q=0,q=1,q=2 and q=3 
 Enter the third column of the CHARECTERISTIC table 
 Enter M for the memory state and T for toggle state
 The order in which you enter the values is important
1 0 1 1

 0 0 1
 0 1 0
 1 0 1
 1 1 1count = 12

00110101
*/

my apologies,

I actually put double qoutes viz;"0"
Thanks a lot for the reply

Arjun
Reputation Points: 10
Solved Threads: 0
Light Poster
arikeri is offline Offline
25 posts
since Mar 2005
Mar 10th, 2005
0

Re: problem printing output

Hi,
I have one more problem now. For the same assignment I need to generate a table of the following king

C++ Syntax (Toggle Plain Text)
  1. a b c.. x1 x1 x3..
  2. 0 0 0 0 0 0
  3. 0 0 0 0 0 1
  4. 0 0 0 0 1 0
  5. .
  6. .
  7. .
  8.  
  9. 0 0 0 1 1 1
  10. 0 0 1 0 0 0
  11. 0 0 1 0 0 0
  12. .
  13. 0 0 1 1 1 1

and so on.

I've shown it for three variables a , b , c (could be more-say k; k is fixed
and three variables x1, x2, x3(could be more-say upto xN.

I am using arrays to store this as both its dimensions are fixed.
The a,b,c need not always go till (1 1 1).Which means that the number of rows for 3 (k)variables a,b,& c may be less than 8 (2^k)


Plz help me out , The submission is in 15 hrs , so its a bit urgent.
Last edited by Dave Sinkula; Mar 10th, 2005 at 4:26 pm. Reason: Used code tags to preserve spacing.
Reputation Points: 10
Solved Threads: 0
Light Poster
arikeri is offline Offline
25 posts
since Mar 2005
Mar 10th, 2005
0

Re: problem printing output

The formatting went wrong.
I've set it right using underscores

a b c.. x1 x1 x3..
0 0 0 __0 _0 _0
0 0 0 __0 _0_ 1
0 0 0 __0 _1 _0
.
.
.

0 0 0 __1_ 1_ 1
0 0 1 __0_ 0_ 0
0 0 1 __0_ 0_ 0
.
0 0 1 __1_ 1_ 1

and so on.
Reputation Points: 10
Solved Threads: 0
Light Poster
arikeri is offline Offline
25 posts
since Mar 2005
Mar 11th, 2005
0

Re: problem printing output

I'm still somewhat fuzzy on what it is you're doing, but then I've got a bit of a cold right now.

Is there anything that you could salvage from the following?
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int r, c, rows, in_c;
  7.  
  8. //
  9. // Get input.
  10. //
  11. cout << "How many input rows? ";
  12. cin >> rows;
  13.  
  14. cout << "How many input columns? ";
  15. cin >> in_c;
  16.  
  17. int **in = new int*[rows];
  18. for ( r = 0; r < rows; ++r )
  19. {
  20. in[r] = new int[in_c];
  21. for ( c = 0; c < in_c; ++c )
  22. {
  23. cout << "Enter input[" << r << "][" << c << "]: ";
  24. cin >> in[r][c];
  25. }
  26. }
  27.  
  28. //
  29. // Get output.
  30. //
  31. int out_c;
  32.  
  33. cout << "How many output columns? ";
  34. cin >> out_c;
  35.  
  36. int **out = new int*[rows];
  37. for ( r = 0; r < rows; ++r )
  38. {
  39. out[r] = new int[out_c];
  40. for ( c = 0; c < out_c; ++c )
  41. {
  42. cout << "Enter output[" << r << "][" << c << "]: ";
  43. cin >> out[r][c];
  44. }
  45. }
  46.  
  47. //
  48. // Do stuff.
  49. //
  50. for ( r = 0; r < rows; ++r )
  51. {
  52. for ( c = 0; c < in_c; ++c )
  53. {
  54. cout << in[r][c] << ' ';
  55. }
  56. cout << " ";
  57. for ( c = 0; c < out_c; ++c )
  58. {
  59. cout << out[r][c] << ' ';
  60. }
  61. cout << '\n';
  62. }
  63.  
  64. //
  65. // Clean up.
  66. //
  67. for ( r = 0; r < rows; ++r )
  68. {
  69. delete[] in[r];
  70. delete[] out[r];
  71. }
  72. delete[] in;
  73. delete[] out;
  74.  
  75. return 0;
  76. }
The input/output I tested was as follows.
C++ Syntax (Toggle Plain Text)
  1. How many input rows? 3
  2. How many input columns? 2
  3. Enter input[0][0]: 1
  4. Enter input[0][1]: 0
  5. Enter input[1][0]: 0
  6. Enter input[1][1]: 1
  7. Enter input[2][0]: 0
  8. Enter input[2][1]: 1
  9. How many output columns? 3
  10. Enter output[0][0]: 1
  11. Enter output[0][1]: 0
  12. Enter output[0][2]: 1
  13. Enter output[1][0]: 0
  14. Enter output[1][1]: 1
  15. Enter output[1][2]: 1
  16. Enter output[2][0]: 1
  17. Enter output[2][1]: 0
  18. Enter output[2][2]: 1
  19. 1 0 1 0 1
  20. 0 1 0 1 1
  21. 0 1 1 0 1
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Clear screen
Next Thread in C++ Forum Timeline: Two C++ questions.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC