Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <iomanip>
- using namespace std;
- void display_header(void);
- void display_result(double atime, double ampere, double voltage);
- void display_max_result(double m_vol, double m_cur, double m_time);
- int main()
- {
- int j, counter;
- double r, v, i_max, f, t, max_current, max_time, max_voltage = 0, i, time, trig, deg, atime;
- const double pi = 3.14159265359;
- char again;
- do
- {
- cout << "Enter your resistance value,R: ";
- cin >> r;
- cout << "Enter your Imax value,Im (in Ampere): ";
- cin >> i_max;
- cout << "Enter your frequency,f (in frequency): ";
- cin >> f;
- display_header();
- for (t = 0; t <= 10; t++)
- {
- time = 100 * (t / f);
- atime = time * 0.001;
- trig = 2 * pi * f * (atime);
- i = i_max * sin(trig);
- v = i * r;
- display_result(time, i, v);
- if (v > max_voltage)
- {
- max_voltage = v;
- max_time = time;
- max_current = i;
- }
- }
- display_max_result(max_voltage, max_voltage, max_time);
- cout.flush();
- cin.ignore();
- cout << endl << "Do you wish to continue ? (Y/N)";
- cin >> again;
- } while (again == 'Y' || again == 'y');
- return 0;
- }
- void display_header(void)
- {
- cout << showpoint << right;
- cout << endl << setw(12) << "Time(ms)" << setw(15) << "Current(A)" << setw(15) << "Voltage(V)" << endl;
- }
- void display_result(double atime, double ampere, double voltage)
- {
- cout << fixed;
- cout << setw(12) << setprecision(2) << atime << setw(15) << setprecision(4) << ampere << setw(15) << setprecision(4) << voltage << endl;
- }
- void display_max_result(double m_vol, double m_cur, double m_time)
- {
- cout << endl << "Vmax is: " << m_vol << "V occurs with current " << m_cur << " at time " << m_time;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement