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

C++ Question. Instead of posting it here please email me the answer. Just say ea

ID: 3569501 • Letter: C

Question

C++ Question.

Instead of posting it here please email me the answer. Just say eamiled. Also please comment on fuctions.

farbod.zolghadr@yahoo.com

Write a program that reads in up to 1000 non-negative integers and displays distinct numbers (i.e., if a number appears multiple times, it is displayed only once). Use the following algorithm: Read each number and store it in an array if it is new. If the number is already in the array, ignore it. The user will indicate that they are done entering numbers by entering a negative number. After the input, the array must contain the distinct numbers. Here is a sample run:

Enter a non-negative integer (negative to quit): 1
Enter a non-negative integer (negative to quit): 2
Enter a non-negative integer (negative to quit): 3
Enter a non-negative integer (negative to quit): 2
Enter a non-negative integer (negative to quit): 1
Enter a non-negative integer (negative to quit): 6
Enter a non-negative integer (negative to quit): 3
Enter a non-negative integer (negative to quit): 4
Enter a non-negative integer (negative to quit): 5
Enter a non-negative integer (negative to quit): 2
Enter a non-negative integer (negative to quit): -4
You entered:
1 2 3 6 4 5
To get credit for this assignment you must use appropriate decomposition! You should have a function to read the numbers and a function to print the resulting array. The function that reads the numbers should call an additional function that reads (and processes) a single number.

Explanation / Answer

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#define size 5

struct stack {

  int s[size];

  int top;

} st;

int stfull() {

  if (st.top >= size - 1)

     return 1;

  else

     return 0;

}

void push(int item) {

  st.top++;

  st.s[st.top] = item;

}

int stempty() {

  if (st.top == -1)

     return 1;

  else

     return 0;

}

int pop() {

  int item;

  item = st.s[st.top];

  st.top--;

  return (item);

}

void display() {

  int i;

  if (stempty())

     printf(" Stack Is Empty!");

  else {

     for (i = st.top; i >= 0; i--)

       printf(" %d", st.s[i]);

  }

}

int main() {

  int item, choice;

  char ans;

  st.top = -1;

  printf(" Implementation Of Stack");

  do {

     printf(" Main Menu");

     printf(" 1.Push 2.Pop 3.Display 4.exit");

     printf(" Enter Your Choice");

     scanf("%d", &choice);

     switch (choice) {

     case 1:

       printf(" Enter The item to be pushed");

       scanf("%d", &item);

       if (stfull())

           printf(" Stack is Full!");

       else

           push(item);

       break;

     case 2:

       if (stempty())

           printf(" Empty stack!Underflow !!");

       else {

           item = pop();

           printf(" The popped element is %d", item);

       }

       break;

     case 3:

       display();

       break;

     case 4:

       exit(0);

     }

     printf(" Do You want To Continue?");

     ans = getche();

  } while (ans == 'Y' || ans == 'y');

return 0;

}

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