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

#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(){


}

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

puzzeled,
arjun

Recommended Answers

All 7 Replies

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.

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

Either that, or use '0' and '1' in the char table.

This isn't helping me either . The function ain't compiling??

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
*/

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

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

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.

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.

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.

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?

#include <iostream>
using namespace std;

int main()
{
   int r, c, rows, in_c;

   //
   // Get input.
   //
   cout << "How many input rows? ";
   cin  >> rows;

   cout << "How many input columns? ";
   cin  >> in_c;

   int **in = new int*[rows];
   for ( r = 0; r < rows; ++r )
   {
      in[r] = new int[in_c];
      for ( c = 0; c < in_c; ++c )
      {
         cout << "Enter input[" << r << "][" << c << "]: ";
         cin  >> in[r][c];
      }
   }

   //
   // Get output.
   //
   int out_c;

   cout << "How many output columns? ";
   cin  >> out_c;

   int **out = new int*[rows];
   for ( r = 0; r < rows; ++r )
   {
      out[r] = new int[out_c];
      for ( c = 0; c < out_c; ++c )
      {
         cout << "Enter output[" << r << "][" << c << "]: ";
         cin  >> out[r][c];
      }
   }

   //
   // Do stuff.
   //
   for ( r = 0; r < rows; ++r )
   {
      for ( c = 0; c < in_c; ++c )
      {
         cout << in[r][c] << ' ';
      }
      cout << "   ";
      for ( c = 0; c < out_c; ++c )
      {
         cout << out[r][c] << ' ';
      }
      cout << '\n';
   }

   //
   // Clean up.
   //
   for ( r = 0; r < rows; ++r )
   {
      delete[] in[r];
      delete[] out[r];
   }
   delete[] in;
   delete[] out;

   return 0;
}

The input/output I tested was as follows.

How many input rows? 3
How many input columns? 2
Enter input[0][0]: 1
Enter input[0][1]: 0
Enter input[1][0]: 0
Enter input[1][1]: 1
Enter input[2][0]: 0
Enter input[2][1]: 1
How many output columns? 3
Enter output[0][0]: 1
Enter output[0][1]: 0
Enter output[0][2]: 1
Enter output[1][0]: 0
Enter output[1][1]: 1
Enter output[1][2]: 1
Enter output[2][0]: 1
Enter output[2][1]: 0
Enter output[2][2]: 1
1 0    1 0 1 
0 1    0 1 1 
0 1    1 0 1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.