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

1. How many bytes of memory is set aside/reserved by the following class declara

ID: 3569481 • Letter: 1

Question

1.

How many bytes of memory is set aside/reserved by the following class declaration? (enter a number, 0-1000)

2.

Each and every class in a C++ program (by convention) are defined in how many files?

In other words, if you have a project and add a new class for it, how many files will you have to add?

Use a number, not words!!!

3.

The C++ language requires that class names be capitalized and match file names.

Select one:

True

False

4.

According to the text, which of the following goes into a header file when you write a class?

Select one or more:

a. implementation

b. function definitions

c. void

d. objects

e. gobal variable declarations

f. class function definitions

g. specification

h. warnings

i. main()

j. scope

5.

For a class, data is usually declared _________________.

Select one:

a. as verbs

b. private

c. last

d. none of the other answers

e. nominally

f. open

g. int

h. public

6.

Which keywords indicate interface scope of the data and methods in a class declaration (in a header file)?

Select one or more:

a. specification

b. struct

c. Write

d. implementation

e. class

f. Time

g. private

h. operation

i. Set

j. scope

k. public

7.

:: is a scope operator that you use to designate which class a function/method belong to.

Select one:

True

False

8. A __________ ( 1 word) is called when you declare a variable (object) of a class's type.

9.

You have to #include a particular class's header file in which of the following files?

Select one or more:

a. none of the above

b. all cpp files that use the class

c. always in main.cpp

d. all other cpp files

e. all other header files that use the class

f. the class's header file

g. the class's cpp file

h. all other header files

Explanation / Answer

#include<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);

}

#include<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);

}