Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that will input a sentence and push each character onto the sta

ID: 3566961 • Letter: C

Question

Create a program that will input a sentence and push each character onto the stack all the while counting the number of characters. Then pop off each character and print them backwards (natural with a stack) and print the length. Like so:


I like burgers!

!sregrub ekil I

The number of characters is 15

Note, don't count the ' ' nor push it onto the stack. The stack should be empty when finished. Use an ".equate" to define a label to reference the top of the stack (can be any name but when you pop off the character, you need to use that label defined by the equate).

Here is what I have so far, any hints will be greatly appreciated:

Br main

ch: .equate 0
count: .equate 2
;top: .equate 4


main: STRO input,d
SUBSP 6,i
LDA 0,i
CHARI ch,s
LDBYTEA ch,s
CHARO ch,s
CPA ch,s
LDA count,s
adda 1,i
sta count,s
STRO numofch,d
DECO count,s
ADDSP 6,i
stop

input: .ASCII "Input a sentence: "
numofch: .ASCII " The number of characters is: "
.end

Explanation / Answer

import java.util.*;
// To include all the classes in util package, for key board i/o
class Demo;
{
   int count=0;
   Public static void main()
   {
       Scanner sc = new Scanner (System.in);
       System.out.println("Enter a string");
       String S= sc. nectLine();
       // string stored in S
      
       int len= S.len(), lastnode;
       for(int i= 0; i< len; i++)
       {
           char c = S.charAt(i);
           lastnode=myStack.push(c);
           if (c== ) break;
          
       }
       System.out.println("Count of char" + count);
       System.out.println("Reverse Stack");
       myStack.pop(lastnode);
   }
  
   public int push (Object item)
   {
       top= new ListNode(item, top);
       top = Next.top;
       count ++;
   }
  
   public void pop(int top)
   {
       if(isEmpty())
       throw new StackUnderflowException("Nothing removed-stack is empty");
       else
       System.out.print(myStack.value(top));
       top = top.getNext();
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote