Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem B: Jukebox Battery Your jukebox has a visual ascii display. You come up with the clever idea of having it display a bar representing

Problem B: Jukebox Battery

Your jukebox has a visual ascii display. You come up with the clever idea of having it display a bar representing how much battery is left. Using the interface to the display, it turns out that you just have to write a void function in C to print out what to display. Your function will take in a percentage and you'll display a bar corresponding to that percentage, with labels on the left-hand side. The function prototype is below. Write your own main to test the function.

// Pre-condition: 0 <= perc <= 100, c is a printable character

// Post-condition: Prints a bar corresponding to perc using the // character c with width 7 and percentage labels

void printBatteryStatus(int perc, char c);

Round perc to the nearest 5% (22% goes to 20% and 43% goes to 45%, for example), and then draw a bar of the character c. Here is what should get printed for perc = 22% and c = '*':

100

95

90

85

80

75

70

65

60

55

50

45

40

35

30

25

20 *******

15 *******

10 *******

5 *******

Battery

battery-scaffold.c

#include  #include  #include  void printBatteryStatus(int perc, char c); int main() { // Get the percentage of battery. int perc; printf("What is the percentage battery you want to display? "); scanf("%d", &perc); // Fix user input. if (perc < 0) perc = 0; if (perc > 100) perc = 100; // Call the function. printBatteryStatus(perc, '*'); return 0; } // Pre-condition: 0 <= perc <= 100, c is a printable character // Post-condition: Prints a bar corresponding to perc using the // character c with width 7 and percentage labels void printBatteryStatus(int perc, char c) { } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago