

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This c++ code defines two classes, series and parallel, which inherit from the abstract class resistor. The classes calculate the total resistance for series and parallel circuits respectively. The user inputs the number of resistances and their values, and the code determines the type of circuit to calculate. The main function initializes the circuit type, inputs the number of resistances and their values, and outputs the total resistance.
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!
1 #include
68 for(int i = 0 ; i < NumR; i++) 69 Hold += 1. 0 F / R[i]; 70 71 Total = 1. 0 F / Hold; 72 73 return Total; 74 } 75 76 ~Parallel() {} 77 }; 78 79 void main() 80 { 81 Resistor* ptr; 82 int choice = 0 ; 83 84 int Num = 0 ; 85 float* Temp; 86 87 char option; 88 89 while( 1 ) 90 { 91 cout<<"Which circuit you want to calculate ( 1 : Series, 2 : Parallel) \n"; 92 cin>>choice; 93 94 if(choice != 1 && choice!= 2 ) 95 { 96 cout<<"Not a Valid choice \n"; 97 cin.clear(); 98 cin.ignore(INT_MAX, '\n'); 99 continue; 100 } 101 102 cout<<"How many resistances are there in your circuit: \n"; 103 cin>>Num; 104 105 Temp = new float[Num]; 106 107 cout<<"Enter the resitance of each resistor: \n"; 108 for(int i = 0 ; i < Num; i++) 109 { 110 cout<<i+ 1 <<" : "; 111 cin>>Temp[i]; 112 } 113 114 switch(choice) 115 { 116 case 1 : 117 ptr = new Series(Num, Temp); 118 cout<<"Total resistance is : "<<ptr‐>total_resistance()<<endl; 119 delete ptr; 120 break; 121 122 case 2 : 123 ptr = new Parallel(Num, Temp); 124 cout<<"Total resistance is : "<<ptr‐>total_resistance()<<endl; 125 delete ptr; 126 break; 127 } 128 129 delete[] Temp; 130 131 132 cout<<"Another (y/n) : ";