PROJECT 1 DESCRIPTION: Write a C++ class definition called SIMPLER_VOIP_FSM whic
ID: 3889194 • Letter: P
Question
PROJECT 1 DESCRIPTION: Write a C++ class definition called SIMPLER_VOIP_FSM which will evaluate the student performance. The prototype for the class SIMPLER_VOIP_FSM is defined as follows: class SIMPLER_VOIP_FSM{ public: // public methods for this class SIMPLER_VOIP_FSM(void); // example: g.SIMPLER_VOIP_FSM(); // constructor; void SIMPLER_VOIP_FSM_READ(void); // example: g.SIMPLER_VOIP_FSM_READ(void); // method to read student grades // returns no values; void SIMPLER_VOIP_FSM_PRINT(void); // example: g.SIMPLER_VOIP_FSM_PRINT(void); // method to print state information; // returns no values; void PRINT_FSM_STATE(int); // example: g.PRINT_FSM_STATE(x); // method to print information related state x; // returns no values; void VERIFY_FSM_STATE(int, int); // example: g.VERIFY_FSM_STATE(x, y); // method to verify if there is a state whose id is x // and whose out degree is y; // returns no values; private: // private var to be used by this class only (not from main) int n; // no of states; int state_id[10]; // ids for states; int out_degree[10]; // no of outgoing edges from a single state; int edge_inputs[10][5]; // inputs for the edges leaving each state; int edge_outputs[10][5]; // outputs for the edges leaving each state; int edge_tail_state_id[10][5]; // ids for the ending states for the // edges leaving each state; }; The objects of SIMPLER_VOIP_FSM class will read the input values from a file called in.1 given with the following format: n state_id_0 x edge_input_0_0 edge_output_0_0 tail_state_id_0_0 ... edge_input_0_x edge_output_0_x tail_state_id_0_x state_id_1 y edge_input_1_0 edge_output_1_0 tail_state_id_1_0 ... edge_input_1_y edge_output_1_y tail_state_id_1_y ... state_id_n-1 z edge_input_n-1_0 edge_output_n-1_0 tail_state_id_n-1_0 ... edge_input_n-1_z edge_output_n-1_z tail_state_id_n-1_z where n (1<= m <= 10) is the number of states, state_id_i (between 0 and 999 inclusive) is the id for a given states, x,y, and z (1<= x,y,z <= 5) are the number of edges leaving state 0, 1, and n-1, respectively, edge_input_i_j is the input for the jth outgoing edge from the ith state, edge_output_i_j is the output for the jth outgoing edge from the ith state, and tail_state_i_j is the id for next state for the jth outgoing edge from the ith state. ____________________________________ An example of SIMPLER_VOIP_FSM constructor is as follows: SIMPLER_VOIP_FSM g(); which instantiates an object g of class SIMPLER_VOIP_FSM. The constructor should initialize all the varaibles to 0. The output to out.1 file is: ++++++++++++++++ START ++++++++++++++++++++++ CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT. ++++++++++++++++ END ++++++++++++++++++++++ MAKE SURE THAT EVERY LINE TO out.1 ENDS WITH A endl. ____________________________________ The definition of SIMPLER_VOIP_FSM_READ method is as follows: g.SIMPLER_VOIP_FSM_READ(); where g is a object of class SIMPLER_VOIP_FSM. This method should read the contents of the in.1 file and populate the private data elements. The output to out.1 is: ++++++++++++++++ START ++++++++++++++++++++++ THERE ARE n STATES IN THIS SIMPLER_VOIP_FSM ++++++++++++++++ END ++++++++++++++++++++++ where n is the number of states. MAKE SURE THAT EVERY LINE TO out.1 ENDS WITH A endl. ____________________________________ The definition of SIMPLER_VOIP_FSM_PRINT method is as follows: g.SIMPLER_VOIP_FSM_PRINT(); where g is a object of class SIMPLER_VOIP_FSM. This method should print the following into out.1: ++++++++++++++++ START ++++++++++++++++++++++ OUTPUT FROM SIMPLER_VOIP_FSM_PRINT INTERFACE: THIS SIMPLER_VOIP_FSM HAS n STATES STATE id_0 HAS x OUTGOING EDGES AS FOLLOWS: EDGE INPUT: in_0_0 EDGE OUTPUT: out_0_0 TAIL STATE: next_state_0_0 ... EDGE INPUT: in_0_x EDGE OUTPUT: out_0_x TAIL STATE: next_state_0_x STATE id_1 HAS y OUTGOING EDGES AS FOLLOWS: EDGE INPUT: in_1_0 EDGE OUTPUT: out_1_0 TAIL STATE: next_state_1_0 ... EDGE INPUT: in_1_y EDGE OUTPUT: out_1_y TAIL STATE: next_state_1_y ... STATE id_n-1 HAS z OUTGOING EDGES AS FOLLOWS: EDGE INPUT: in_n-1_0 EDGE OUTPUT: out_n-1_0 TAIL STATE: next_state_n-1_0 ... EDGE INPUT: in_n-1_z EDGE OUTPUT: out_n-1_z TAIL STATE: next_state_n-1_z ++++++++++++++++ END ++++++++++++++++++++++ where n is the number of states and x, y, and z are the outdegrees for states 0, 1, and n-1, respectively. MAKE SURE THAT EVERY LINE TO out.1 ENDS WITH A endl. ____________________________________ google-chrome The definition of PRINT_FSM_STATE method is as follows: g.PRINT_FSM_STATE(x); where g is a object of class SIMPLER_VOIP_FSM and x is an integer. If there is a state whose id is x, the output to out.1 file is: ++++++++++++++++ START ++++++++++++++++++++++ OUTPUT FROM PRINT_FSM_STATE INTERFACE: STATE x HAS z OUTGOING EDGES AS FOLLOWS: EDGE INPUT: in_x_0 EDGE OUTPUT: out_x_0 TAIL STATE: next_state_x_0 ... EDGE INPUT: in_x_z EDGE OUTPUT: out_x_z TAIL STATE: next_state_x_z ++++++++++++++++ END ++++++++++++++++++++++ where z is the outdegree for state x. If there is no such state, the output ot out.1 is: ++++++++++++++++ START ++++++++++++++++++++++ OUTPUT FROM PRINT_FSM_STATE INTERFACE: THIS FSM DOES NOT HAVE A STATE WITH ID x. ++++++++++++++++ END ++++++++++++++++++++++ MAKE SURE THAT EVERY LINE TO out.1 ENDS WITH A endl. ____________________________________ The definition of VERIFY_FSM_STATE method is as follows: g.VERIFY_FSM_STATE(x, y); where g is a object of class SIMPLER_VOIP_FSM and x and y are integers. If there is a state whose id is x and whose outdegree is y, the output to out.1 is: ++++++++++++++++ START ++++++++++++++++++++++ OUTPUT FROM VERIFY_FSM_STATE INTERFACE: THIS FSM HAS A STATE WITH ID x AND OUTDEGREE OF y. ++++++++++++++++ END ++++++++++++++++++++++ If there x and/or y does match, the output to out.1 is: ++++++++++++++++ START ++++++++++++++++++++++ OUTPUT FROM VERIFY_FSM_STATE INTERFACE: THIS FSM DOES NOT HAVE A STATE WITH ID x AND OUTDEGREE OF y. ++++++++++++++++ END ++++++++++++++++++++++ MAKE SURE THAT EVERY LINE TO out.1 ENDS WITH A endl. ____________________________________ Your header file will be used by our staff as a header file called p1.h. 2 examples of main functions utilizing such a header are as follows: :::::::::::::: EXAMPLE 1 ::::::::::::::::::::: ---------CONTENTS OF main1.cc FILE:----------- #include #include "p1.h" // example program: main1.cc int main () { SIMPLER_VOIP_FSM g; // instantiate an object g which is of class STATE g.SIMPLER_VOIP_FSM_READ(); // READ THE CONTENTS OF in.1 g.PRINT_FSM_STATE(12); return 0; } ---------CONTENTS OF in.1 FILE:--------------- 4 10 1 100 500 11 11 3 101 501 12 102 502 13 103 503 10 12 2 102 502 13 103 503 10 13 1 103 503 10 ---------EXPECTED CONTENTS OF out.1 FILE:----- ++++++++++++++++ START ++++++++++++++++++++++ CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT. ++++++++++++++++ END ++++++++++++++++++++++ ++++++++++++++++ START ++++++++++++++++++++++ THERE ARE 4 STATES IN THIS SIMPLER_VOIP_FSM ++++++++++++++++ END ++++++++++++++++++++++ ++++++++++++++++ START ++++++++++++++++++++++ OUTPUT FROM PRINT_FSM_STATE INTERFACE: STATE 12 HAS 2 OUTGOING EDGES AS FOLLOWS: EDGE INPUT: 102 EDGE OUTPUT: 502 TAIL STATE: 13 EDGE INPUT: 103 EDGE OUTPUT: 503 TAIL STATE: 10 ++++++++++++++++ END ++++++++++++++++++++++ :::::::::::::: EXAMPLE 2 ::::::::::::::::::::: ---------CONTENTS OF main2.cc FILE:----------- #include #include "p1.h" // example program: main2.cc int main () { SIMPLER_VOIP_FSM g; // instantiate an object g which is of class STATE g.SIMPLER_VOIP_FSM_READ(); // READ THE CONTENTS OF in.1 g.SIMPLER_VOIP_FSM_PRINT(); // PRINT THE PRIVATE DATA INTO out.1 FILE g.VERIFY_FSM_STATE(11, 3); // VERIFY THAT STATE 11 WITH OUTDEGREE 3 // EXISTS IN FSM return 0; } ---------CONTENTS OF in.1 FILE:--------------- 4 10 1 100 500 11 11 3 101 501 12 102 502 13 103 503 10 12 2 102 502 13 103 503 10 13 1 103 503 10 ---------EXPECTED CONTENTS OF out.1 FILE:----- ++++++++++++++++ START ++++++++++++++++++++++ CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT. ++++++++++++++++ END ++++++++++++++++++++++ ++++++++++++++++ START ++++++++++++++++++++++ THERE ARE 4 STATES IN THIS SIMPLER_VOIP_FSM OUTPUT FROM SIMPLER_VOIP_FSM_PRINT INTERFACE: THIS SIMPLER_VOIP_FSM HAS 4 STATES STATE 10 HAS 1 OUTGOING EDGES AS FOLLOWS: EDGE INPUT: 100 EDGE OUTPUT: 500 TAIL STATE: 11 STATE 11 HAS 3 OUTGOING EDGES AS FOLLOWS: EDGE INPUT: 101 EDGE OUTPUT: 501 TAIL STATE: 12 EDGE INPUT: 102 EDGE OUTPUT: 502 TAIL STATE: 13 EDGE INPUT: 103 EDGE OUTPUT: 503 TAIL STATE: 10 STATE 12 HAS 2 OUTGOING EDGES AS FOLLOWS: EDGE INPUT: 102 EDGE OUTPUT: 502 TAIL STATE: 13 EDGE INPUT: 103 EDGE OUTPUT: 503 TAIL STATE: 10 STATE 13 HAS 1 OUTGOING EDGES AS FOLLOWS: EDGE INPUT: 103 EDGE OUTPUT: 503 TAIL STATE: 10 ++++++++++++++++ END ++++++++++++++++++++++ ++++++++++++++++ START ++++++++++++++++++++++ OUTPUT FROM VERIFY_FSM_STATE INTERFACE: THIS FSM HAS A STATE WITH ID 11 AND OUTDEGREE OF 3. ++++++++++++++++ END ++++++++++++++++++++++ Anonymous wrote solution for it: #include #include using namespace std; class SIMPLER_VOIP_FSM { public: ofstream out; SIMPLER_VOIP_FSM() { n = 0; for (int i = 0; i < 10; i++) { state_id[i] = 0; out_degree[i] = 0; } for (int i = 0; i < 10; i++) { for (int j = 0; j < 5; j++) { edge_inputs[i][j] = 0; edge_outputs[i][j] = 0; edge_tail_state_id[i][j] = 0; } } out.open("example.txt"); out << " ++++++++++++++++ START ++++++++++++++++++++++ " << endl; out << "CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT." << endl; out << "++++++++++++++++ END ++++++++++++++++++++++ " << endl; } // method to read student grades void SIMPLER_VOIP_FSM_READ(void) { out << "++++++++++++++++ START ++++++++++++++++++++++" << endl; out << "THERE ARE n STATES IN THIS SIMPLER_VOIP_FSM " << endl; out << "++++++++++++++++ END ++++++++++++++++++++++" << endl; } void SIMPLER_VOIP_FSM_PRINT(void) // method to print state information; { out << "THIS SIMPLER_VOIP_FSM HAS n STATES" << endl; out << " ++++++++++++++++ END ++++++++++++++++++++++" << endl; } void PRINT_FSM_STATE(int x) // method to print information related state x; { out << "++++++++++++++++START++++++++++++++++++++++" << endl; /*OUTPUT FROM PRINT_FSM_STATE INTERFACE : STATE x HAS z OUTGOING EDGES AS FOLLOWS : EDGE INPUT : in_x_0 EDGE OUTPUT : out_x_0 TAIL STATE : next_state_x_0 ... EDGE INPUT : in_x_z EDGE OUTPUT : out_x_z TAIL STATE : next_state_x_z */ // OUTPUT FROM PRINT_FSM_STATE INTERFACE: THIS FSM DOES NOT HAVE A STATE WITH ID x. out << "++++++++++++++++END++++++++++++++++++++++" << endl; } void VERIFY_FSM_STATE(int x, int y) // method to verify if there is a state whose id is x // and whose out degree is y; { out << "++++++++++++++++START++++++++++++++++++++++" << endl; //OUTPUT FROM VERIFY_FSM_STATE INTERFACE : THIS FSM HAS A STATE WITH ID x AND OUTDEGREE OF y. //THIS FSM DOES NOT HAVE A STATE WITH ID x AND OUTDEGREE OF y out << "++++++++++++++++END++++++++++++++++++++++" << endl; } private: int n; // no of states int state_id[10]; // ids for states int out_degree[10]; // no of outgoing edges from a single state int edge_inputs[10][5]; // inputs for the edges leaving each state int edge_outputs[10][5]; // outputs for the edges leaving each state int edge_tail_state_id[10][5]; // ids for the ending states for the edges leaving each state }; int main() { SIMPLER_VOIP_FSM g; g.SIMPLER_VOIP_FSM_READ(); system("pause"); return 0; } //working on input file read.
Q: How to put input students' records and get output (Ubuntu Linux platform)
Explanation / Answer
#include<iostream>
#include<fstream>
using namespace std;
class SIMPLER_VOIP_FSM
{
public:
ofstream out;
SIMPLER_VOIP_FSM()
{
n = 0;
for (int i = 0; i < 10; i++)
{
state_id[i] = 0;
out_degree[i] = 0;
}
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 5; j++)
{
edge_inputs[i][j] = 0;
edge_outputs[i][j] = 0;
edge_tail_state_id[i][j] = 0;
}
}
out.open("example.txt");
out << " ++++++++++++++++ START ++++++++++++++++++++++ " << endl;
out << "CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT." << endl;
out << "++++++++++++++++ END ++++++++++++++++++++++ " << endl;
}
// method to read student grades
void SIMPLER_VOIP_FSM_READ(void)
{
out << "++++++++++++++++ START ++++++++++++++++++++++" << endl;
out << "THERE ARE n STATES IN THIS SIMPLER_VOIP_FSM " << endl;
out << "++++++++++++++++ END ++++++++++++++++++++++" << endl;
}
void SIMPLER_VOIP_FSM_PRINT(void) // method to print state information;
{
out << "THIS SIMPLER_VOIP_FSM HAS n STATES" << endl;
out << " ++++++++++++++++ END ++++++++++++++++++++++" << endl;
}
void PRINT_FSM_STATE(int x) // method to print information related state x;
{
out << "++++++++++++++++START++++++++++++++++++++++" << endl;
/*OUTPUT FROM PRINT_FSM_STATE INTERFACE :
STATE x HAS z OUTGOING EDGES AS FOLLOWS : EDGE INPUT : in_x_0 EDGE OUTPUT : out_x_0 TAIL STATE :
next_state_x_0 ... EDGE INPUT : in_x_z EDGE OUTPUT : out_x_z TAIL STATE : next_state_x_z
*/
// OUTPUT FROM PRINT_FSM_STATE INTERFACE: THIS FSM DOES NOT HAVE A STATE WITH ID x.
out << "++++++++++++++++END++++++++++++++++++++++" << endl;
}
void VERIFY_FSM_STATE(int x, int y) // method to verify if there is a state whose id is x // and whose out degree is y;
{
out << "++++++++++++++++START++++++++++++++++++++++" << endl;
//OUTPUT FROM VERIFY_FSM_STATE INTERFACE : THIS FSM HAS A STATE WITH ID x AND OUTDEGREE OF y.
//THIS FSM DOES NOT HAVE A STATE WITH ID x AND OUTDEGREE OF y
out << "++++++++++++++++END++++++++++++++++++++++" << endl;
}
private:
int n; // no of states
int state_id[10]; // ids for states
int out_degree[10]; // no of outgoing edges from a single state
int edge_inputs[10][5]; // inputs for the edges leaving each state
int edge_outputs[10][5]; // outputs for the edges leaving each state
int edge_tail_state_id[10][5]; // ids for the ending states for the edges leaving each state
};
int main()
{
SIMPLER_VOIP_FSM g;
g.SIMPLER_VOIP_FSM_READ();
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.