struct circuit
that stores the resistances of
three different resistors and a boolean value indicating whether the
three resistors are in series or parallel.
Declare struct circuit
and a typedef to Circuit
in circuit.h. Store the resistances using double precision
floating point numbers./* main.c */
// create at least two different circuits (one parallel and one serial)
// and use both draw_circuit(.) and print_circuit(.) on each of them
int main();
/* circuit.c, circuit.h */
// return the total resistance of the circuit
double calc_circuit_resistance(Circuit c);
/* in ui.c, ui.h */
// read the resistances from stdin
// also ask the user whether a parallel or series connection is used
// return a new circuit struct containing the above data
Circuit read_circuit();
// print a visual representation of the struct; this can be something like
// -[220Ω]-[330Ω]-[220Ω]- and
//
// ┌[220Ω]┐
// ─┼[330Ω]┼─
// └[220Ω]┘
void draw_circuit(Circuit c);
// print the values of the resistors, whether a parallel or series connection
// is used and the total resistance
void print_circuit(Circuit c);
Declare all functions in the corresponding header files and include the
header files wherever needed. Make sure to use #include
guards in each of the header files.
main(.)
to use your
new code.Item
.
Each Item
stores
unsigned
holding the quantity of devices availabledouble
holding the value (resistance, capacity, ...)/* inventory.c, inventory.h */
// Return the total number of resistors in the inventory.
// Eg. there are 100 resistors with 330 ohm, 50 with 5600 ohm and 10 with
// 2 megaohm, the total number is 160.
size_t count_resistors(Item items[], size_t count);
// Return the total number of capacitors in the inventory.
size_t count_capacitors(Item items[], size_t count);
/* interface.c, interface.h */
// ask the user to enter a new item on the command-line;
// add the new item to the given list and return the count increased by one
// (since there is one more element in the inventory array)
size_t add_item(Item items[], size_t count);
// print given item to stdout
void print_item(Item i);
// print all items, one per line
void print_items(Item items[], size_t count);
// command-line interface to create and manage an inventory
// start a loop that asks the user which action they want to perform
// `a` -> create a new item and add it to the inventory array
// `c` -> show the number of capacitors
// `e` -> exit the program
// `i n` -> show the n-th item (0-indexed) of the inventory array
// `h` -> show this help text
// `l` -> show the list of items
// `r` -> show the number of resistors
void cli();
In main(.)
call cli()
. Create
an array of items of sufficient size inside of cli()
.
all
- compile everythingclean
- clean up everything