Exemple #1
0
// Reads messages file and pushes email messages to the stack
void readmessages(StackType& email, ifstream& in)
{
	Message message; // Redo the constructor

	while (!(in.eof())) {

		char Body[1000];
		char FROM[6], sender[50];
		char DATE[6], date[15];
		char SUBJECT[9], subject[60]; // Body, sender,date, and subject initialized as character arrays

		in >> FROM;
		in.ignore(1);
		in.getline(sender,50);
		in >> DATE >> date;
		in >> SUBJECT;
		in.ignore(1);
		in.getline(subject,60);
		in.ignore(100,'\n');  // reads the data from messagesfile.txt

		in.get(Body,1000,'#');

		message.setSender(sender);
		message.setDate(date);
		message.setSubject(subject);
		message.setBody(Body); // Sets the information into a message object

		email.Push(message);   // Pushes the message object onto the emails stack

		in.ignore(100,'\n');
	}
}
int main()
{
  char symbol;
  StackType stack;
  bool balanced = true;
  char openSymbol;
  
  cout << "Enter an expression and press return." << endl;
  cin.get(symbol); 

  while (symbol != '\n' && balanced)
  {
    if (IsOpen(symbol))
      stack.Push(symbol);

	else if (IsClosed(symbol))
    {
      if (stack.IsEmpty())
        balanced = false;
      else
      {
        openSymbol = stack.Top();
        stack.Pop();
        balanced = Matches(symbol, openSymbol);
      }
    }
    cin.get(symbol);
  }

  if (balanced)
    cout << "Expression is well formed." << endl;
  else
    cout << "Expression is not well formed."  << endl;
  return 0;
}
Exemple #3
0
int main()
{
  bool palindrome = true;
  char character;
  StackType stack;
  QueType queue(40);
  char stackChar;
  char queChar;
  cout << "Enter a string; press return." << endl;
  cin.get(character);
  while (character != '\n')
  {
    stack.Push(character);
    queue.Enqueue(character);
    cin.get(character);
  }
  
  while (palindrome && !queue.IsEmpty())
  {
    stackChar = stack.Top();
    stack.Pop();
    queue.Dequeue(queChar);
   
    if (stackChar != queChar)
      palindrome = false;
  }
  
  if (palindrome)
    cout << "String is a palindrome" << endl;
  else
    cout << "String is not a palindrome" << endl;
  return 0;
}