Click here to Skip to main content
15,891,204 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Socket help.. Pin
valikac2-Dec-02 14:29
valikac2-Dec-02 14:29 
GeneralCode Timing Question Pin
_Kal-El_2-Dec-02 11:00
_Kal-El_2-Dec-02 11:00 
GeneralRe: Code Timing Question Pin
Kannan Kalyanaraman2-Dec-02 20:24
Kannan Kalyanaraman2-Dec-02 20:24 
GeneralFILETIME conversion/comparison Pin
#realJSOP2-Dec-02 10:34
mve#realJSOP2-Dec-02 10:34 
GeneralRe: FILETIME conversion/comparison Pin
Nitron2-Dec-02 11:08
Nitron2-Dec-02 11:08 
GeneralRe: FILETIME conversion/comparison Pin
Jamie Hale2-Dec-02 11:33
Jamie Hale2-Dec-02 11:33 
GeneralRe: FILETIME conversion/comparison Pin
Michael Dunn2-Dec-02 12:15
sitebuilderMichael Dunn2-Dec-02 12:15 
GeneralQueue problem (part2) Pin
ian_ok2-Dec-02 10:24
ian_ok2-Dec-02 10:24 
Ok I've changed things around and it is as good as working apart from.....

1. If the queue has been emptied (after input) and I then try to view the queue I'd like a message no data in queue, have tried various methods to no avail, at the moment it just returns to main menu, as it runs void show and shows nothing as it should, but I want that message!!

2. My queue size isn't owrking i can have a queue of 3 and it will allow a 4th to be entered, yet NOT store this (GOOD), but would be better to not allow the 4th to be entered.

Thanks in advance.

Ian

2.
#include<iostream.h><br />
class Queue<br />
{<br />
private:<br />
  int *input;<br />
  int Array_Size;<br />
  int first;//memory location<br />
  int last;//memory location<br />
public:<br />
  Queue(int);<br />
  ~Queue();<br />
  void push(int);<br />
  int pop();<br />
  void show();<br />
};<br />
<br />
Queue::Queue(int data)<br />
{<br />
  Array_Size=data + 1;<br />
  // Allocates the proper amount + 1 for error checking<br />
  input = new int[Array_Size];<br />
  first=Array_Size;<br />
  last=0;<br />
}<br />
<br />
Queue::~Queue()<br />
{<br />
  delete input; // Clean up<br />
}<br />
//Entering students in the queue<br />
void Queue::push(int info)<br />
{<br />
  if ( first == last + 1 ) <br />
  {<br />
    cout<<"Queue is full\n";<br />
    return;<br />
  }<br />
<br />
  input[last++] = info; // Insert<br />
  last %= Array_Size; // Wrap the queue<br />
}<br />
//Viewing of students seen or error message<br />
int Queue::pop()<br />
{<br />
  if ( first % Array_Size == last ) <br />
  {<br />
    cout<<"\n\nNo students waiting in the queue\n";<br />
    return -1;<br />
  }<br />
<br />
  first %= Array_Size; // Wrap the queue<br />
  return input[first++]; // Remove<br />
}<br />
<br />
//Allows the viewing of the queue or returns to main menu if none to show<br />
void Queue::show()<br />
{<br />
	 int it = first;<br />
   while  ( it != last )<br />
  {<br />
    it %= Array_Size;<br />
    cout<<"|"; cout<<input[it++]; cout<<"| ";<br />
  }<br />
<br />
}<br />
<br />
int menu()<br />
{<br />
  //Main menu view as a switch<br />
	int choice = 0;<br />
  cout<<"\n\n\t\t**MAIN MENU**";<br />
  cout<<"\n\n\t1\tStudent number to join the queue";<br />
  cout<<"\n\t2\tStudent seen (Remove from queue)";<br />
  cout<<"\n\t3\tView the students in the queue";<br />
  cout<<"\n\t4\tEXIT";<br />
  cout<<"\n\n\tPlease enter your choice : ";<br />
  cin>>choice;<br />
  return choice;<br />
}<br />
<br />
int main()<br />
{<br />
  int StudentID = 0; //initalise to 0 allowing error checking in menu option 3<br />
  int qsize;<br />
  int option;<br />
  int set=0;<br />
  <br />
  cout<<"\n\tPlease enter the length of the Queue : ";<br />
  cin>>qsize;<br />
  set = qsize;<br />
  //error checking for invalid queue size<br />
  while (qsize<1 ||qsize>15)<br />
  {	<br />
	cout<<"\nNot a valid queue size, must be between 1 and 15";<br />
	cout<<"\nTry again: ";<br />
	cin>>qsize;<br />
  }<br />
  Queue q(qsize);<br />
  do<br />
  {<br />
    option = menu();<br />
    switch(option)<br />
    {<br />
    case 1:<br />
		//error checking for invalid StudentID input<br />
	  cout<<"\n\t* * Valid student numbers between 1 and 500 only * *\n";<br />
      cout<<"\nEnter the student number : ";<br />
      cin>>StudentID;<br />
      while  (StudentID < 1 || StudentID > 500)<br />
      {<br />
        cout<<"Invalid entry try again: ";<br />
        cin>>StudentID;<br />
      }<br />
	  //Storing the StudentID in a location and output to screen<br />
	  q.push(StudentID);<br />
      cout<<"\nStudent "<<StudentID<<" has been inserted into queue.";<br />
      break;<br />
    case 2:<br />
		/*Error checking for deleting student if not = to -1 then delete<br />
		 show error message from the pop*/<br />
      if ( ( StudentID = q.pop() ) != -1 )<br />
		  cout<<"\nStudent "<<StudentID<<" has been deleted from the queue.";<br />
	   break;<br />
    case 3:<br />
		/*Error checking if no students entered at all<br />
		the if -1 allows for if option 2 is pressed first<br />
		as StudentID is set to this at that stage*/<br />
		if (StudentID==0||StudentID==-1)<br />
		{<br />
			cout<<"\nNo students entered yet!";<br />
			break;<br />
		}<br />
<br />
			//Show the queue if StudentID stored<br />
			//Return to menu if no StudentID's stored<br />
      q.show();<br />
      break;<br />
    case 4:<br />
		//Exit mode<br />
		cout<<"\n** GOODBYE **\n";<br />
      break;<br />
    default://message if input not valid by use of while command below<br />
      cout<<"\nIncorrect entry, try again with 1,2,3 or 4.";<br />
    }<br />
  }<br />
  while (option!=4);<br />
}

GeneralRe: Queue problem (part2) Pin
Christian Graus2-Dec-02 10:55
protectorChristian Graus2-Dec-02 10:55 
GeneralResizing a CFormView class Pin
Georgi Atanasov2-Dec-02 10:12
Georgi Atanasov2-Dec-02 10:12 
GeneralRe: Resizing a CFormView class Pin
Maximilien2-Dec-02 10:50
Maximilien2-Dec-02 10:50 
GeneralWrite to parallel port Pin
Shay Harel2-Dec-02 10:03
Shay Harel2-Dec-02 10:03 
Generalhelp: right mouse click pop up menu Pin
trustno12-Dec-02 8:50
trustno12-Dec-02 8:50 
GeneralRe: help: right mouse click pop up menu Pin
valikac2-Dec-02 8:57
valikac2-Dec-02 8:57 
GeneralRe: help: right mouse click pop up menu Pin
Jason Henderson2-Dec-02 9:16
Jason Henderson2-Dec-02 9:16 
GeneralRe: help: right mouse click pop up menu Pin
Nitron2-Dec-02 10:00
Nitron2-Dec-02 10:00 
GeneralWizardsheet - propertypage and AfxMessageBox Pin
André Dewispelaere2-Dec-02 8:35
André Dewispelaere2-Dec-02 8:35 
GeneralCListCtrl + Report View + ... Problem Pin
mickelthepickle2-Dec-02 8:00
mickelthepickle2-Dec-02 8:00 
GeneralRe: CListCtrl + Report View + ... Problem Pin
pranavamhari2-Dec-02 14:44
pranavamhari2-Dec-02 14:44 
GeneralUDP and port 0 Pin
Dave_2-Dec-02 7:31
Dave_2-Dec-02 7:31 
GeneralRe: bind and port numbers Pin
Le centriste2-Dec-02 7:40
Le centriste2-Dec-02 7:40 
GeneralRe: bind and port numbers Pin
Dave_2-Dec-02 7:56
Dave_2-Dec-02 7:56 
GeneralRe: bind and port numbers Pin
Rickard Andersson202-Dec-02 8:04
Rickard Andersson202-Dec-02 8:04 
GeneralRe: bind and port numbers Pin
Dave_2-Dec-02 8:24
Dave_2-Dec-02 8:24 
GeneralRe: bind and port numbers Pin
Rickard Andersson202-Dec-02 8:34
Rickard Andersson202-Dec-02 8:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.