0% found this document useful (0 votes)
259 views

PROGRAM Charging and Discharging

This C++ program calculates the charging and discharging of a capacitor. The user inputs the resistance, capacitance, time, and whether they want to calculate charging or discharging. It uses the formula for time in the charging/discharging equation. For charging, it calculates 1-(e^(-t/(RC))) and for discharging it calculates e^(-t/(RC)), printing the result as a percentage of the maximum charge Q.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
259 views

PROGRAM Charging and Discharging

This C++ program calculates the charging and discharging of a capacitor. The user inputs the resistance, capacitance, time, and whether they want to calculate charging or discharging. It uses the formula for time in the charging/discharging equation. For charging, it calculates 1-(e^(-t/(RC))) and for discharging it calculates e^(-t/(RC)), printing the result as a percentage of the maximum charge Q.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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