Hi for me this is th first time that I use c++. I have to do this exercise. Somebody can help me?
Thanx.
Implement a FIFO-queue ( first in, first out ) as a ring buffer. Use a static array as the data structure. The program needs to be able to add elements to the end of the queue, tell the value of the oldest element and remove from the queue. The capacity n of the ring buffer is 10000 elements.
The program must handle the following commands:
L k Read in an integer k, push it to the end of the queue and print "L". If the queue is already full, just print an error message "V".
T Print the value of the oldest element in the queue. If the queue is empty, print "V".
P Print the value of the oldest element in the queue and remove it from the queue. If the queue is empty, print "V".
Q End the program execution. Print "the end".
You can assume the following when implementing the program:
1. All the integers are between -1000000 - +1000000
2. The input lines are at best 75 characters long
3. No undefined commands are given. All commands and their elements are separated with one or more white space character (space, tab stop, newline).
Thanx for the help
5 4374 Meetee 931
Recognized Expert Moderator Contributor
Hi for me this is th first time that I use c++. I have to do this exercise. Somebody can help me?
Thanx.
Implement a FIFO-queue ( first in, first out ) as a ring buffer. Use a static array as the data structure. The program needs to be able to add elements to the end of the queue, tell the value of the oldest element and remove from the queue. The capacity n of the ring buffer is 10000 elements.
The program must handle the following commands:
L k Read in an integer k, push it to the end of the queue and print "L". If the queue is already full, just print an error message "V".
T Print the value of the oldest element in the queue. If the queue is empty, print "V".
P Print the value of the oldest element in the queue and remove it from the queue. If the queue is empty, print "V".
Q End the program execution. Print "the end".
You can assume the following when implementing the program:
1. All the integers are between -1000000 - +1000000
2. The input lines are at best 75 characters long
3. No undefined commands are given. All commands and their elements are separated with one or more white space character (space, tab stop, newline).
Thanx for the help
Please don't just explain your requirements, also attach your efforts. Here we cannot give you readymade code. Kindly have a look to posting guidelines.
Regards
I have made two file:
MAIN:
it doesn't work.
RedSon 5,000
Recognized Expert Expert
Have you learned about pointers yet?
Usually FIFOs are implemented using pointers, you can read more about them on wikipedia.
not yet, but you can help me?
do you know what is my problems?
Ganon11 3,652
Recognized Expert Specialist
Well, you haven't implemented the functionality of a circular queue correctly. By your method, I can add 10000 elements, remove 10000 elements, and try to add an element. When I try to do so, I will get an error (because last == 10000), even though there are no elements in the queue any longer. Rethink how to implement this circular queue before continuing to write functions.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tobias Pfeiffer |
last post by:
Hi!
I want to write a "client-server-application" (only running on the same
machine) or actually I've already begun with and have problems with the
interprocess communication. The server, when...
|
by: Luca |
last post by:
I have the need of a container of integers showing both the
characteristics of an associative container (all integer elements
different from each other) and the FIFO behaviour.
Do you know if...
|
by: Michele Moccia |
last post by:
How can I implement a "time critical" fifo in c++ ?
I just have to manage sequences of raw bytes, no user defined types.
An std::queue<unsigned char> or std::deque<unsigned char> seems to be slow....
|
by: Jack |
last post by:
I want to implement a fixed-size FIFO queue for characters.
I only want to use array not linked list.
For example,
const int N = 10;
char c_array;
The question is when the queue is full,...
|
by: David Bear |
last post by:
I'm looking to see if there are any examples or prewritting fifo queue
classes. I know this is a broad topic. I'm looking to implement a simple
application where a web server enqueue and pickle...
| |
by: mai |
last post by:
Hi everyone,
i'm trying to exhibit FIFO anomaly(page replacement algorithm),, I
searched over 2000 random strings but i couldnt find any anomaly,, am
i I doing it right?,, Please help,,,The...
|
by: gulvaiz |
last post by:
Dear Members,
Hi I'm Shahzad form PAKISTAN.
I want stock in FIFO system.
let suppose i have two tables, pur, and sale,
now i want results like that
Date Transction Description ...
|
by: kvivek002 |
last post by:
hi
how to write a code in C which implements FIFO policy with using only arrays?
(by using HIT AND MISS)...
|
by: Arepi |
last post by:
Hi!
Wath's sense of this line?
open ( FILE, "+>fifo");
Thanks!
|
by: sazd1 |
last post by:
Hi Student2
I am working on similar kind of thing for stock calculation but could not find any solution to my problem even after putting my problem to different forums.
I saw your post that you...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |