Author: George Wanis Ayed Wanis
Student ID: 2300280
Project: C++ Programming Project
This program calculates the total electrical resistance of a circuit that contains resistors connected in series and parallel.
The user provides a single input string that describes the circuit, and the program evaluates it step by step until the final equivalent resistance is obtained.
The program supports:
- Series operations using
Sors - Parallel operations using
Porp - End of operation using
Eore
You must enter the circuit description as a single line.
- Use
S(ors) for series group - Use
P(orp) for parallel group - End each group with
E(ore) - Separate resistor values using spaces or commas
- Only numbers,
S,P,E, spaces, commas and dots are allowed - Any other character will result in "Wrong Description"
S 10 20 E
Means: 10Ω and 20Ω in series
P 10 20 30 E
Means: 10Ω, 20Ω, 30Ω in parallel
Nested example: S 10 P 20 30 E 40 E
Means: 10Ω in series with (20Ω || 30Ω) in series with 40Ω
-
The program first checks the input for invalid characters.
If something invalid is found, it prints: Wrong Description -
It repeatedly finds the last
SorPin the string. -
It finds the matching
Eafter it. -
It extracts the numbers between them.
-
It calculates:
- Series:
R = R1 + R2 + ... - Parallel:
R = 1 / (1/R1 + 1/R2 + ...)
- It replaces the whole operation with the computed equivalent value.
- This continues until no
SorPremain.
Finally, it prints: The total resistance =
Compile:
bash
g++ -o resistance main.cpp
Run:
./resistance Then paste your circuit description and press Enter.
Example Runs Input:
S 10 20 30 E Output:
The total resistance = 60 Input:
P 10 20 30 E Output:
The total resistance = 5.45455 Input:
S 10 P 20 30 E 40 E Output:
The total resistance = 50 Important Notes Series must contain at least 2 resistors, otherwise:
Incorrect Input Parallel must contain at least 3 resistors, otherwise:
Incorrect Input The program supports nested operations naturally
Input must strictly follow the described format
License This project was created for educational purposes as part of a university assignment.