Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PRINTQUEUE.H #include #include using namespace std; void print_queue(queue q) { while (!q.empty()) { cout int sum_queue(queue q) { int sum = 0; while (!q.empty()) {

image text in transcribed

image text in transcribed

PRINTQUEUE.H

#include #include

using namespace std;

void print_queue(queue q) { while (!q.empty()) { cout

int sum_queue(queue q) { int sum = 0; while (!q.empty()) { sum+=q.front(); q.pop(); } return sum; }

Write a program named mov avg.cpp that calculates the moving average of a queue. A queue is much like a vector but may only be modified by adding to the back (by calling q.push(int)), and removing from the front (by calling q.pop)); refer to the code below (queue example) to see the functionality of member functions push) and pop). Note that, a queue's elements cannot be accessed by square brackets [] Use a queue to calculate a moving average of a growing, i.e., the average of only the last 3 elements of the queue as shown in the program output example below. The program should stop when the user enters -1. Refer to the sample output for required print-outs; there are only single spaces Note: Include the library printqueue.h (given in supplementary folder). This library pro- vides a function to print the queue, as well as a function to calculate the sum of a queue Open, read and try to understand the functionality of this library. You do NOT need to change anything in this header file Queue example queue q; q.push(1); q.push (2); q.push(3); print queue (q)

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_2

Step: 3

blur-text-image_3

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago