#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(){ }
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.
This isn't helping me either . The function ain't compiling??
#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(){
}/* 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.
A sample run is then as follows.#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(){ }
/* 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 */
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
#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; }
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
| DaniWeb Message | |
| Cancel Changes | |