First of all id like to say Hi! im new to this forum and stumbled upon it via google really realllly need some help with this assignment im doing at University, i'm missing something pretty fundamental i think.
I have two classes, I first run the userdisplay and get values...these values are then calculated in the other class...but i cant get the classes to see the private variables such as Resistance. I have created 2 header files and 2 Cpp files
Code:
//Main Function - Responsible for Running program
//All C++ Projects need a main function
#include <iostream>
using namespace std;
#include "RLCSeriesCircuit.h"
#include "Simulation.h"
int main (void)
{
char Restart; //declare variable restart as type char
do
{
system("CLS"); //Clears the Screen (Stage 2 on Activity)
Simulation mySimulation; //object
mySimulation.Userdisplay(); //executes first function
cout << "\nDo you want to Restart the Program? (y/n): " ; //loop to restart whole program
cin >> Restart; //stores into char variable restart
}
while (Restart== 'y'); //Restarts if user enters in character y
cout << "\nEnd of program\n\n"; //outputs simple statement stating program has ended
system ("Pause"); //Pauses Program and displays "press any key to continue"
return 0;
}
Code:
//Header File for CLass Simulation
//Created by Daniel Jackson
#include <iostream>
using namespace std;
class Simulation
{
public:
void Userdisplay(void);
private:
double Resistance;
double Inductance;
double Capacitance;
double VS;
double MinFreq;
double MaxFreq;
double Freqsteps;
};
Code:
//Simulation C++ File
//Created by Daniel Jackson
#include <iostream>
#include <iomanip>
using namespace std;
#include <cmath>
using std::pow;
using std::log;
using std::setprecision;
#include <string>
using std::string;
using std::getline;
#include "Simulation.h" //include Simulation Class Definition
#include "RLCSeriesCircuit.h" //include RLCSeriesCircuit class defniition
void Simulation::Userdisplay () //1st Function (User inputs)
{
cout << "**********************************************************\n"; //user display (start)
cout << "* 205SE Assignment *\n";
cout << "* Created by Daniel Jackson (SID: 1641552) *\n";
cout << "* This program simulates the behaviour of an *\n";
cout << "* RLC circuit based on user inputs *\n";
cout << "**********************************************************\n";
cout << "\nRLC Series circuit Simulation"; //Program Title (Stage 3 of Activity)
cout << "\nEnter the values for the circuit components:\n";
cout << "\nPlease enter Resistance value[Ohms] -> "; //Prompt for R (Stage 4 of Activity)
cin >> Resistance; //Read in R (Stage 4 of Activity)
cout << "\nPlease enter Inductance value[H] -> "; //Pompt for L (Stage 4 of Activity)
cin >> Inductance; //Read in L (Stage 4 of Activity)
cout << "\nPlease enter Capacitance value[F] -> "; //Prompt for C (Stage 4 of Activity)
cin >> Capacitance; //Read in C (Stage 4 of Activity)
cout << "\nEnter the operating conditions:\n";
cout << "Enter supply Voltage [V] -> "; //prompt for supply voltage
cin >> VS; //Read in supply Voltage
cout << "Enter Min Supply frequency [Hz] -> "; //prompt for minimum supply frequency
cin >> MinFreq; //Read in Minimum Frequency
cout << "Enter Max supply frequency [Hz] -> "; //prompt for maximum frequency
cin >> MaxFreq; //Read in Maximum Frequency
cout << "Enter No. of frequency steps required -> "; //prompt for number of freq steps
cin >> Freqsteps;
RLC_Series_Cct Circuit;
Circuit.getResistance();
Circuit.getCapacitance();
Circuit.getInductance();
Circuit.Incrementloop();
}
Code:
//Header file for RLC Series CIrcuit
//Created by Daniel Jackson
#include <iostream>
using namespace std;
class RLC_Series_Cct
{
public:
void Incrementloop();
double getResistance();
double getInductance();
double getCapacitance();
private:
double actualFreq;
double Z;
double I;
double VR;
double NF;
double XL;
double XC;
double VOVR;
int iteration;
int Maxstep;
};
Code:
//RLC Series Circuit C++ File
//Created by Daniel Jackson
#include <iostream>
#include <iomanip>
using namespace std;
#include <cmath>
using std::pow;
using std::log;
using std::setprecision;
#include <string>
using std::string;
using std::getline;
#include "Simulation.h"
#include "RLCSeriesCircuit.h"
const double pi = 3.1415926535; //Global constant
double RLC_Series_Cct::getResistance()
{
return Resistance;
}
double RLC_Series_Cct::getCapacitance()
{
return Capacitance;
}
double RLC_Series_Cct::getInductance()
{
return Inductance;
}
void RLC_Series_Cct::Incrementloop() //2nd function (calculation with for loop)
{
cout << right; // one time exectution
cout.fill ('*');
NF = (((2*pi*sqrt(Inductance*Capacitance()))/1)); //Calculate Natural Frequency
Maxstep = ((log10(MaxFreq) - log10(MinFreq))/(0.1)); //incerement calculation
cout << "Voltage ratio plot at each frequency step:\n\n"; //introduces chart
for (iteration= 1; iteration<= Maxstep; iteration++) //for loop begins
{
actualFreq = (MinFreq * pow(10.0, (0.1 * iteration))); // plot Voltage ratio
XL = (2 * pi * actualFreq * Inductance); //Calculation
XC = (1/ (2 * pi * actualFreq * Capacitance)); //Calculation
Z = (sqrt(Resistance * Resistance + (XL - XC) * (XL - XC))); //Calculation
I = (VS / Z); //Calculation
VR = (I * Resistance); //Calculation
VOVR = (VR / VS); //Calculation
cout << setw(VOVR * 100) << actualFreq << setprecision (2) << endl;
}
cout << "\nNatural frequency of circuit = " << NF << setprecision( 2 ); //outputs Natural Frequency to user
}
1>c:\data\jacks1d\my documents\visual studio 2008\projects\rlc project 2\rlc project 2\rlcseriescircuit.cpp(42) : error C2065: 'MaxFreq' : undeclared
identifier
1>c:\data\jacks1d\my documents\visual studio 2008\projects\rlc project 2\rlc project 2\rlcseriescircuit.cpp(32) : error C2065: 'Inductance' : undeclared identifier
1>c:\data\jacks1d\my documents\visual studio 2008\projects\rlc project 2\rlc project 2\rlcseriescircuit.cpp(27) : error C2065: 'Capacitance' : undeclared identifier
Examples of the errors im getting are above...seems no matter what i try i cannot call them variables....