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;
- 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;
- cout<<showpoint<<right;
- cout<<endl<<setw(12)<<"Time(ms)"<<setw(15)<<"Current(A)"<<setw(15)<<"Voltage(V)"<<endl;
- 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;
- cout<<fixed;
- cout<<setw(12)<<setprecision(2)<<time<<setw(15)<<setprecision(4)<<i<<setw(15)<<setprecision(4)<<v<<endl;
- if(v>max_voltage)
- {
- max_voltage=v;
- max_time=time;
- max_current=i;
- }
- }
- cout<<endl<<"Vmax is: "<<max_voltage<<"V occurs with current "<<max_current<<" at time "<<max_time;
- cout.flush();
- cin.ignore();
- cout<<endl<<"Do you wish to continue ? (Y/N)";
- cin>>again;
- }
- while (again =='Y' ||again== 'y');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement