I have made some adjustments to the program, but I still need to finish it. If anyone has any suggestions PLEASE reply. I need all the help I can get!
CODE
#include <iostream>
#include <cmath>
#include <ctime>
#include <fstream>
#include <iomanip>
using namespace std;
//Generator Class:
class generator
{
public:
void chooseDistribution(); // choose between uniform or normal
void numberOfSteps(); //sets the # of time steps
void setFrequency(); //sets non-signal frequency
void sendDelimiter(generator& G); //sends delimiter to receiver when no signal
void makeSignal(generator& G); //generates random ints and chars to form signal
//void saveRun(generator& G, receiver& R); saves to file and shows results
private:
int number; //variable to store random number
char letter; //variable to store random letter
int choiceD;
double valueD;
int steps;// number of iteration times
int frequency;
int delimiter; //non-signals
char delimChar;
int delimInt;
int signal;
};
double normal(const double &mean, const double &sdiv)
{
static const double pii=3.1415927;
static const double r_max=RAND_MAX+1;
return sdiv*sqrt(-2*log((rand()+1)/r_max))*sin(2*pii*rand()/r_max)+mean;
}
void generator::chooseDistribution()
{
cout << "1. Uniform Distribution" << endl;
cout << "2. Normal Distribution" << endl << endl;
cout << "Choose 1 or 2: ";
cin >> choiceD;
cout << endl;
if (choiceD==1) //write up uniform distribution function
{
cout << "You chose uniform distribution." << endl;
}
else
{
cout << "You chose normal distribution." << endl; //to test
double mean;
double sd;
cout <<"What mean? ";
cin >> mean;
cout << "Standard deviation? ";
cin >> sd;
cout << endl;
valueD = normal(mean,sd);
cout << "testing: Value of normal dist is " << valueD << endl << endl;
}
}
void generator::numberOfSteps()
{
cout << "How many time steps? " << endl;
cin >> steps;
}
void generator::setFrequency()
{
cout << "What frequency of non-signal time steps? " << endl;
cin >> frequency;
}
void generator::sendDelimiter(generator& G)
{
G.numberOfSteps();
G.setFrequency();
delimiter = steps*(frequency/100);
delimChar = '*';
delimInt = -1;
}
void generator::makeSignal(generator& G)
{
srand(time(NULL));
int r;
G.sendDelimiter(G);
G.numberOfSteps();
while (delimiter <= steps)
if (delimiter!=0 && steps!=0)
{
delimChar = letter;
delimInt = number;
}
else
{
number = rand()%10;
r = rand()%10;
letter = 'A' + r;
}
signal = letter,number;
cout << "testing the signal: " << signal << endl << endl;
return;
}
//Receiver Class:
class receiver
{
public:
void initializeReceiver(); //displays the signals that have been stored into the matrix
void drawMatrix(receiver& R);
private:
int matrix[10][10]; //variable to store a 10x10 matrix of integers (signals)
};
void receiver::initializeReceiver()
{
char row;
int col;
//initializes the entire matrix to zero
for (row = 0; row < 10; row++)
for (col = 0; col < 10; col++)
matrix[row][col] = 0;
}
void receiver::drawMatrix(receiver& R)
{
int k;
system("cls");
cout<<endl<<endl;
cout<<setw(38)<<"_______________________________"<<endl;
for(int row=0; row<10; row++)
{
cout<<setw(8)<<"|";
for(int i=0; i<10; i++)
{
cout<<setw(10)<<"|";
}
cout<<endl;
cout<<setw(8)<<"|";
for(int i=0; i<10; i++)
{
k=row*10+i;
cout<<setw(5)<<matrix[k]<<setw(5)<<"|";
}
cout<<endl;
cout<<setw(8)<<"|";
for(int i=0; i<10; i++)
{
cout<<setw(10)<<"_________|";
}
cout<<endl;
}
cout<<endl<<endl;
}
//Other functions
void showSelection();
void saveRun(generator& G,
receiver& R); //saves to file and runs simulation
int main()
{
generator G;
receiver R;
int choice; //variable to hold the selection
showSelection();
cin >> choice;
cout << endl;
//saveRun();
while (choice !=6)
{
switch (choice)
{
case 1:
R.initializeReceiver();
break;
case 2:
G.chooseDistribution();
break;
case 3:
G.numberOfSteps();
break;
case 4:
G.setFrequency();
break;
case 5:
saveRun(G, R);
break;
default:
cout << "Invalid Selection." << endl <<endl;
}
showSelection();
cin >> choice;
cout << endl;
}
return 0;
}
void showSelection() //User Menu
{
cout << "************** Time-Stepping Simulations **************" << endl << endl;
cout << "1. Initialize the receiver" << endl;
cout << "2. Choose distribution type" << endl;
cout << "3. Set number of time steps" << endl;
cout << "4. Set relative frequency of non-signal time steps" << endl;
cout << "5. Save to file and run simulation" << endl;
cout << "6. Quit" << endl << endl;
cout << "Choose from options 1-6: ";
}
void saveRun()
{
}