Struct variables solution

$19.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (2 votes)

Struct variables

A Create a header file capacitor.h.

Protect your header using #ifndef directive.

Define a struct with tag Capacitor that holds the following information about a capacitor:

Model number (e.g. 11-123U), capacitance (e.g. 1000 uf), voltage (e.g. 2.5 V), cost ($6.50)

Create your main program file capacitorsInfo.c that uses the header file you just declared.

Declare two variables of type struct Capacitor and populate them with the following values:

First variable: model is 11-123U, capacitance is 100, voltage is 25 and cost is $6.00

Second variable: model is 65T91a, capacitance is 22000, voltage is 20 and cost is $25.00

Print the the model number of the first capacitor and the voltage of the second.

Create a makefile to build your program. Make sure it compiles and runs without errors.

Remove your print statements.

Struct Array

Add a third Capacitor variable and initialize it from values entered by the user. Use fgets when reading

the model number to make sure you don�t exceed the size of your model number array.

Print to the standard output the members of the third capacitor and to make sure the capacitor is

populated correctly.

Declare an array of Capacitors of size 4 and copy the three capacitors you created to the array.

Populate the fourth element of the array from user input.

Manipulation with Functions

Add a function displayCapacitorInfo that takes a capacitor as input parameter and prints its details in the

following format:

Capacitor 11-123U:

* Capacitance 100 uF

* Voltage: 25 V

* Cost: $25.00

Call your function on all members of the array.

Using typedef

Change the struct definition from using tag name to using typedef.

Modify your program to work properly with the new definition.

Add a function largestCapacitance that takes as input an array of Capacitors and returns a pointer to the

Capacitor with the largest capacitance.

Call largestCapacitance on your array and add statements to print the cost of the capacitor returned by

the function.

Using Enum

In the header file capacitor.h, define an enumeration CapType with the following values:

Ceramic, Aluminum, Film, Supercapacitor

Add a new member, capacitor type, to your struct Capacitor.

Update the capacitor type member of all elements of the array to a type of your choice.

Update the displayCapacitorInfo function to print the capacitor type as well.