Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

PROGRAM

// charging discharging.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream> //Calculate Charging and Discharging of Capacitor
#include<conio.h>
#include<cmath>
using namespace std;
int main()
{
float q1,q2, Q, t, r, c, T,e=2.73;
int op;
cout << "Q is the max. value of charge given by battery! "<<endl; //Statement
cout << "Enter value of resistance? ";
cin >> r;
cout << "Enter value of capacitance? ";
cin >> c;
cout << "Enter time ? ";
cin >> t;
T = -t / (r*c); //formula
cout << "Enter 1 for charging and 2 discharging of capacitor? ";
cin >> op;
switch (op)
{
case 1:
q1 = 1-(pow (e,T));
cout << "Charging of capacitor =" << q1 << "Q";
cout << endl;
break;
case 2:
cout << endl;
q2 = pow(e,T);
cout << "Discharging of capacitor =" << q2<< "Q";
cout<<endl;
break;
}
system("pause");
return 0;
}
Output: (For Charging): Output: (For Discharging):

You might also like