Advertisement
khaiwen1111

MW lab

Jan 1st, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int j,counter;
  11.     double r,v,i_max,f,t,max_current,max_time,max_voltage=0,i,time,trig,deg,atime;
  12.     const double pi =3.14159265359;
  13.     char again;
  14.   do
  15.    {
  16.       cout<<"Enter your resistance value,R: ";
  17.       cin>>r;
  18.       cout<<"Enter your Imax value,Im  (in Ampere): ";
  19.       cin>>i_max;
  20.       cout<<"Enter your frequency,f (in frequency): ";
  21.       cin>>f;
  22.    
  23.       cout<<showpoint<<right;
  24.       cout<<endl<<setw(12)<<"Time(ms)"<<setw(15)<<"Current(A)"<<setw(15)<<"Voltage(V)"<<endl;
  25.    
  26.    
  27.       for(t=0;t<=10;t++)
  28.       {
  29.           time=100*(t/f);
  30.           atime=time*0.001;
  31.           trig=2*pi*f*(atime);
  32.           i=i_max*sin(trig);
  33.           v=i*r;
  34.           cout<<fixed;
  35.           cout<<setw(12)<<setprecision(2)<<time<<setw(15)<<setprecision(4)<<i<<setw(15)<<setprecision(4)<<v<<endl;
  36.        
  37.           if(v>max_voltage)
  38.           {
  39.             max_voltage=v;
  40.             max_time=time;
  41.             max_current=i;
  42.           }
  43.       }
  44.    
  45.       cout<<endl<<"Vmax is: "<<max_voltage<<"V occurs with current "<<max_current<<" at time "<<max_time;
  46.       cout.flush();
  47.       cin.ignore();
  48.       cout<<endl<<"Do you wish to continue ? (Y/N)";
  49.       cin>>again;
  50.    }
  51.    while (again =='Y' ||again== 'y');
  52.  
  53.    return 0;
  54.    
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement