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

Console Welcome to the Customer Invoices Report frankjones@yahoo.com 10504M 11/1

ID: 3569522 • Letter: C

Question

Console

Welcome to the Customer Invoices Report

frankjones@yahoo.com          10504M   11/18/04   $99.00

frankjones@yahoo.com          10501M   10/25/04   $59.50

johnsmith@hotmail.com         10505M   11/18/04   $297.50

johnsmith@hotmail.com         10500M   10/25/04   $495.00

seagreen@levi.com             10502M   10/25/04   $99.00

wendyk@warners.com            10503M   10/25/04   $112.00

Operation

This application connects to a database and displays a list of all customers and their invoices. Each line in this report includes the customer

Explanation / Answer

nclude<stdio.h>

#include<conio.h>

#include<stdlib.h>

#define MAX 50

int size;

// Defining the stack structure

struct stack {

  int arr[MAX];

  int top;

};

// Initializing the stack(i.e., top=-1)

void init_stk(struct stack *st) {

  st->top = -1;

}

// Entering the elements into stack

void push(struct stack *st, int num) {

  if (st->top == size - 1) {

     printf(" Stack overflow(i.e., stack full).");

     return;

  }

  st->top++;

  st->arr[st->top] = num;

}

//Deleting an element from the stack.

int pop(struct stack *st) {

  int num;

  if (st->top == -1) {

     printf(" Stack underflow(i.e., stack empty).");

     return NULL;

  }

  num = st->arr[st->top];

  st->top--;

  return num;

}

void display(struct stack *st) {

  int i;

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

     printf(" %d", st->arr[i]);

}

int main() {

  int element, opt, val;

  struct stack ptr;

  init_stk(&ptr);

  printf(" Enter Stack Size :");

  scanf("%d", &size);

  while (1) {

     printf(" tSTACK PRIMITIVE OPERATIONS");

     printf(" 1.PUSH");

     printf(" 2.POP");

     printf(" 3.DISPLAY");

     printf(" 4.QUIT");

     printf(" ");

     printf(" Enter your option : ");

     scanf("%d", &opt);

     switch (opt) {

     case 1:

       printf(" Enter the element into stack:");

       scanf("%d", &val);

       push(&ptr, val);

       break;

     case 2:

       element = pop(&ptr);

       printf(" The element popped from stack is : %d", element);

       break;

     case 3:

       printf(" The current stack elements are:");

       display(&ptr);

       break;

     case 4:

       exit(0);

     default:

       printf(" Enter correct option!Try again.");

     }

  }

  return (0);