Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:16:52+00:00 2026-06-11T13:16:52+00:00

For my current assignment, I have to use the following header file, #ifndef STACK_H

  • 0

For my current assignment, I have to use the following header file,

#ifndef STACK_H
#define STACK_H

template <class T, int n>
class STACK
{
  private:
    T a[n];
    int counter;

  public:
    void MakeStack() {
        counter = 0;
    }

    bool FullStack() {
        return (counter == n) ? true : false ;
    }

    bool EmptyStack() {
        return (counter == 0) ? true : false ;
    }

    void PushStack(T x) {
        a[counter] = x;
        counter++;
    }

    T PopStack() {
        counter--;
        return a[counter];
    }
};

#endif

To write a program that will take a sentence, store it into the “stack”, and then display it in reverse, and I have to allow the user to repeat this process as much as they want. The thing is, I am NOT allowed to use arrays (otherwise I wouldn’t need help with this), and am finding myself stumped.

To give an idea of what I am attempting, here is my code as of posting, which obviously does not work fully but is simply meant to give an idea of the assignment.

#include <iostream>
#include <cstring>
#include <ctime>
#include "STACK.h"
using namespace std;

int main(void)
{
    auto time_t a;
    auto STACK<char, 256> s;
    auto string curStr;
    auto int i;

    // Displays the current time and date
    time(&a);
    cout << "Today is " << ctime(&a) << endl;

    s.MakeStack();
    cin >> curStr;
    i = 0;
    do
    {
        s.PushStack(curStr[i]);
        i++;
    } while (s.FullStack() == false);

    do
    {
        cout << s.PopStack();
    } while (s.EmptyStack() == false);

    return 0;
} // end of "main"

UPDATE
This is my code currently

#include   <iostream>
#include   <string>
#include   <ctime>
#include   "STACK.h"
using namespace std;

time_t                      a;
STACK<char, 256>        s;
string             curStr;
int                     i;
int                     n;

// Displays the current time and date
time(&a);
cout << "Today is " << ctime(&a) << endl;

s.MakeStack();
getline(cin, curStr);
i = 0;
n = curStr.size();
do
{
   s.PushStack(curStr[i++]);
    i++;
}while(i < n);

do
{
    cout << s.PopStack();
}while( !(s.EmptyStack()) );    

return 0;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:16:53+00:00Added an answer on June 11, 2026 at 1:16 pm

    You’re on the right track, but you shouldn’t be looping until the stack is full — there are no guarantees curStr consists of at least 256 characters. Instead, loop like as follows…

    int n = curStr.size();
    do {
      s.PushStack(curStr[i++]);
    } while (i < n);
    

    Now, you should really not write <bool-expr> == false or <bool-expr> == true… instead, merely write !<bool-expr> and <bool-expr>, respectively. You don’t need all of your auto storage specifiers on the local variables, either. Your professor should also look into using the constructor rather than using MakeStack.

    edit: It appears you had some trouble translating my code. You only need to i++ once per loop — this increments our position in the string. As you are doing it now, you are actually incrementing the position twice and thus only pushing every other character.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Current Process: I have a tar.gz file. (Actually, I have about 2000 of them,
I have some sites powered by Joomla, but with my current assignment I wanted
I have a class assignment where I have to write a program that will
My current homework assignment has me creating an iterator class for a list. I'm
I'm in a data structures class and we have an assignment that includes creating
I have been trying to complete the following assignment for my college. So far,
I'm pretty new to C# and got this assignment. I have a class called
So I have an assignment that I have to use Tkinter to create a
My current assignment in a beginning Java course is to animate a circle across
I have the following C struct from the source code of a server, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.