Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Marks: 1.5 Due: Beginning of your lab in week 10. Write a working C program that

ID: 3734574 • Letter: M

Question

Marks: 1.5 Due: Beginning of your lab in week 10. Write a working C program that will calculate the total capacitance, electrical charge, and rms voltage drops across the set of two capacitors in series when connected to a 12V a.c. supply as shown below: C1 C2 Vc2 C1 Requirements: 1. Include comments at the beginning of the program as shown below: program: lab6.c author: firstName, lastName date: today's date purpose: using switch case statement 2. First, user is prompted to enter two capacitance values representing capacitors C, and C2. 3. The program then displays the following menu: 1. Calculate and display the total capacitance (CT) 2. Calculate and display the voltage drops for each resistor (Vcs Va) 3. Calculate and display the electrical charge (QT) User is asked to enter 1, 2, or 3 to select one of three options displayed on the screen Published on Mar 8

Explanation / Answer

ScreenShot

-----------------------------------------------------------------------------------------------------------------------------------------------

Code:-

/*
program: lab6.c
author : firstname,lastname
date   : today' date
purpose: using switch-case statement
*/

//Header file
#include <stdio.h>
//Main method
int main(void) {
   //variables declaration
   double c1,c2,CT,Vs=12,Vc1,Vc2,Qc1,QT;
   int ch;
//promt user for first and second capacitance
    printf("Enter the first capacitance : ");
    scanf("%lf",&c1);
    printf(" Enter the second capacitance : ");
    scanf("%lf",&c2);
    //Display menus for user's
    printf("               MENU FOR CALCULATION       ");
    printf("          1.Calculate and display the total capacitance(CT) .");
    printf("          2.Calculate and display the voltage drop for each resistor(Vc1,Vc2) .");
    printf("          1.Calculate and display the total electrical charge(QT) .");
    //Ask user to enter their chice
    printf("    Please enter your choice from 1-3 : ");
    scanf("%d",&ch);
    //According to that choice do the calculations and display output
    switch(ch){
       //calculating total capacitance and display the output
       case 1:
           CT=(c1*c2)/(c1+c2);
           printf("    The total capacitance(CT) = %.2fFard",CT);
           break;
           //calculate voltage drop of resistors and display the value
       case 2:
           CT=(c1*c2)/(c1+c2);
           Vc1=Vs*(CT/c1);
           Vc2=Vs*(CT/c2);
           printf("    The voltage drop of resistor1(Vc1) = %.2fVolt and resistor2(Vc2) = %.2fVolt",Vc1,Vc2);
           break;
           //Calculate and display electrical charge
       case 3:
           CT=(c1*c2)/(c1+c2);
           Vc1=Vs*(CT/c1);
           Qc1=Vc1*c1;
           QT=Qc1;
           printf("    The total electrical charge(QT) = %.2fcoulomb",QT);
           break;
           //choice other than 1-3 shows error
       default:
           printf("    This is not a valid option!!");
           break;
    }//end of switch
   return 0;
}


----------------------------------------------------------------------------------------

Output:-