Write the function definitions for the following five function prototypes shown in Listing-1 called in main. Function definitions go below main starting at the comment shown in Listing-2
Write the function definitions for the following five function prototypes shown in Listing-1 called in main. Function definitions go below main starting at the comment shown in Listing-2
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Write the function definitions for the following five function prototypes shown in Listing-1 called
in main. Function definitions go below main starting at the comment shown in Listing-2
![Listing 2: main
1 #include <iostream>
2 #include <string >
3 #define CATEGORIES 5
4
5 // Prototypes go here
6.
7 // main is shown complete, DO NOT MODIFY
8 int main (){
std:: string categories [CATEGORIES];
double values [CATEGORIES]; double total{ 0.0 }; int lcl{ 0 };
9.
10
11
12
while (true) {
get_category (categories);
get_values (values, categories);
compute_total (total, values);
get_longest_category_name (lcl, categories);
13
14
15
16
17
<< "\nCategories as
a Percentage of \
the Total (category_amount/" << total
18
std::cout
19
<< ")\n";
20
std::cout
くく
21
\n";
bar_chart (categories, values, lcl, total);
<< "\nEnter y to
23
std :: cout
another bar chart, \
%3D
create
24
or any other key to exit: ";
25
std:: cout <<"\n";
std :: string response; std:: cin >> response;
if (response != "y")
26
27
break;
28
1cl
= 0; total
0.0;
29
}//while
30 }//main
31 //
32 // Implementations go below
33 //](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5498129d-fa90-4054-9767-1cffe54599e5%2F27fef429-e269-4b5b-a90e-a74a9d98c551%2Fxcf7bdn_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Listing 2: main
1 #include <iostream>
2 #include <string >
3 #define CATEGORIES 5
4
5 // Prototypes go here
6.
7 // main is shown complete, DO NOT MODIFY
8 int main (){
std:: string categories [CATEGORIES];
double values [CATEGORIES]; double total{ 0.0 }; int lcl{ 0 };
9.
10
11
12
while (true) {
get_category (categories);
get_values (values, categories);
compute_total (total, values);
get_longest_category_name (lcl, categories);
13
14
15
16
17
<< "\nCategories as
a Percentage of \
the Total (category_amount/" << total
18
std::cout
19
<< ")\n";
20
std::cout
くく
21
\n";
bar_chart (categories, values, lcl, total);
<< "\nEnter y to
23
std :: cout
another bar chart, \
%3D
create
24
or any other key to exit: ";
25
std:: cout <<"\n";
std :: string response; std:: cin >> response;
if (response != "y")
26
27
break;
28
1cl
= 0; total
0.0;
29
}//while
30 }//main
31 //
32 // Implementations go below
33 //
![2. Write the function definitions for the following five function prototypes shown in Listing-1 called
in main. Function definitions go below main starting at the comment shown in Listing-2
Listing 1: prototypes
1 //function 1: reads five category names
into the cat array
2 void get _category (std : : string
cat [CATEGORIES]);
3
//function 2: gets five values for each category
5 void get_values (double values [CATEGORIES], std::string cat[CATEGORIES]);
4
6.
7 //function 3: computes the total value and stores in total
8 void compute_total(double& total, double vals [CATEGORIES]);
9.
10 //function 4:
computes the longest category name
and stores in longest
11 void get_longest_category_name (int& longest, std:: string cat [CATEGORIES]);
12
13 //function 5: prints to std:cout the five category bar chart
14 void bar_chart (std:: string cat [CATEGORIES], \
15
double values [CATEGORIES], int lcl, double total);](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5498129d-fa90-4054-9767-1cffe54599e5%2F27fef429-e269-4b5b-a90e-a74a9d98c551%2Fljlp48r_processed.jpeg&w=3840&q=75)
Transcribed Image Text:2. Write the function definitions for the following five function prototypes shown in Listing-1 called
in main. Function definitions go below main starting at the comment shown in Listing-2
Listing 1: prototypes
1 //function 1: reads five category names
into the cat array
2 void get _category (std : : string
cat [CATEGORIES]);
3
//function 2: gets five values for each category
5 void get_values (double values [CATEGORIES], std::string cat[CATEGORIES]);
4
6.
7 //function 3: computes the total value and stores in total
8 void compute_total(double& total, double vals [CATEGORIES]);
9.
10 //function 4:
computes the longest category name
and stores in longest
11 void get_longest_category_name (int& longest, std:: string cat [CATEGORIES]);
12
13 //function 5: prints to std:cout the five category bar chart
14 void bar_chart (std:: string cat [CATEGORIES], \
15
double values [CATEGORIES], int lcl, double total);
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY