Questions
Complete the following functions in the Stack.java/Stack.h files (ATTACHED BELOW): a. void push(int val) b. int...

Complete the following functions in the Stack.java/Stack.h files (ATTACHED BELOW):
a. void push(int val)
b. int pop()
c. int getSize()

public class Stack {
  
private int maxStackSize, topOfStack;
private int[] stack;
  
public Stack(int maxStackSize) {
if (maxStackSize <= 0)
System.out.println("Stack size should be a positive integer.");
else {
this.maxStackSize = maxStackSize;
topOfStack = -1;
stack = new int[maxStackSize];
}
}
  
public void push(int val) { // complete this function
}
  
public int pop() { // complete this function
}
  
public int getSize() { // complete this function
}
}


In: Computer Science

C Program: Create a C program that prints a menu and takes user choices as input....

C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output.

Your code must contain at least one of all of the following control types:

  • nested for() loops
  • a while() or a do-while() loop
  • a switch() statement
  • an if-else statement
  • functions (see below)

Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?

The first thing your program will do is print a menu of choices for the user. You may choose your own version of the wording or order of choices presented, but each choice given in the menu must match the following:

Menu Choice Valid User Input Choices
Enter/Change Character 'C' or 'c'
Enter/Change Number 'N' or 'n'
Draw Line 'L' or 'l'
Draw Square 'S' or 's'
Draw Rectangle 'R' or 'r'
Draw Triangle (Left Justified) 'T' or 't'
Quit Program 'Q' or 'q'


A prompt is presented to the user to enter a choice from the menu. If the user enters a choice that is not a valid input, a message stating the choice is invalid is displayed and the menu is displayed again.

Your executable file will be named Lab3_<username>_<labsection>

Your program must have at least five functions (not including main()) including:

  • A function that prints the menu of choices for the user, prompts the user to enter a choice, and retrieves that choice. The return value of this function must be void. The function will have one pass-by-reference parameter of type char. On the function's return, the parameter will contain the user's menu choice.
  • A function that prompts the user to enter a single character. The return value of the function be a char and will return the character value entered by the user. This return value will be stored in a local variable, C, in main(). The initial default value of this character will be ' ' (blank or space character).
  • A function that prompts the user to enter a numerical value between 1 and 15 (inclusive). If the user enters a value outside this range, the user is prompted to re-enter a value until a proper value is entered. The return value of the function be an int and will return the value entered by the user. This return value will be stored in a local variable, N, in main(). The initial default value of this character will be 0.
  • A function for each geometric shape. Each function will take the previously entered integer value N and character value C as input parameters (You will need to ensure that these values are valid before entering these functions). The return values of these functions will be void. The functions will print the respective geometric shape of N lines containing the input character C. N is considered the height of the shape. For a line, it is just printing the character in C, N number of times, so that it creates a vertically standing line of length N. For N = 6 and C = '*', the draw line function should output:

    *
    *
    *
    *
    *
    *


    If a square is to be printed, then the following output is expected:
    ******
    ******
    ******
    ******
    ******
    ******


    In case of a rectangle, we assume its width is N+5. It should look like the following:
    ***********
    ***********
    ***********
    ***********
    ***********
    ***********


    If the user selects Triangle, then it should print a left justified triange which looks like the following:

    *
    **
    ***
    ****
    *****
    ******

Suggested Steps to Complete the Assignment:

You are not required to complete the following steps to write your program or even pay attention to them. However, these steps will give you an idea on how to create C programs that are stable and need less debugging. If you do decide to use the suggested steps, you should test your program thoroughly to ensure each step works correctly before moving on to the next step.

  1. Create a source file with only your main() function and the standard #include files. Compile and run (it won't do anything, but if you get compile errors, it is best to fix them immediately).
  2. Write a function, called from main(), that prints the menu. Compile and test it to ensure it works properly.
  3. Add a pass-by-reference parameter to your menu() function that will retrieve the character input within the function and make it available for use within the main function. The menu function must remain a void function and not return a value.
  4. Add code to the menu() function to prompt and retrieve user input (allow any character), and assign that input character to the pass-by-reference parameter). Compile and test your code.
  5. Enclose the print menu function and user input code within a loop that will exit the program when the Quit program choice is entered. Test the logic of your code to ensure that the loop only exits on proper input ('q' or 'Q').
  6. Create five "stub functions" for the six other (non-Quit) choices. Put a print statement such as "This is function EnterChar()" or some other informative statement in the body of the function. For functions that return a value, return a specific character 'X' or number. This will be changed when the function is filled in.
  7. Within the loop in main(), create the logic to call each function based on input from the menu choice (and handle incorrect input choices). Test this logic by observing the output of the stub function statements.
  8. Fill in the logic and code for each function. Note that the Line drawing function is probably a little easier (logically) to write than the Right Justified Printing function, so you may want to write it first. Once you have the Line drawing function complete, think about what additional character(s) you will have to print (and how many) to make a square shape. Step by step, you can write functions for other shapes as well. This is the part of the lab (and the course) where you develop your skills to create algorithms that solve specific problems. These kinds of skills are not specific to C or any other language, but how to implement these algorithms are language specific.
  9. Test your program thoroughly.

In: Computer Science

I need my code output values edited to be formatted to two decimal places (i believe...

I need my code output values edited to be formatted to two decimal places (i believe using setprecision), i will need you to edit my code toformat each menu option to 2 decimal places: provided is my code

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
   double radius;
   double base;
   double height;
   double length;
   double width;
   double Area;
   const double PI = 3.14159;
   int choice;

   // display menu
   cout << "Geometry Calculator" << endl << endl;
   cout << " 1. Calculate the Area of a Circle" << endl;
   cout << " 2. Calculate the Area of a Rectangle" << endl;
   cout << " 3. Calculate the Area of a Triangle" << endl;
   cout << " 4. Quit" << endl << endl;
   cout << "Enter your choice (1-4):" << endl;
   cin >> choice;

   //validate and process the menu

   switch(choice)
   {
       case 1:

           cout << "\n";
           cout << "Enter the radius of the circle: ";
           cin >> radius;

           if (radius > 0)
           {
               Area = PI * radius * radius;

               cout << "\n";
               cout << "Area of Circle is: " << Area << setprecision(2) << endl;

           }
           else
           {
               cout << "The radius can not be less than zero. Only enter positive values for your radius.";
           }
           break;

       case 2:

           cout << "\n";
           cout << "Enter the length of the rectangle: ";
           cin >> length;
           cout << "Enter the width of the rectangle: ";
           cin >> width;

           if (length > 0 && width > 0)
           {
               Area = length * width;

               cout << "\n";
               cout << "Area of Rectangle is: " << Area << endl;
           }
           else
           {
               cout << "\nOnly enter positive values for length and width.";
           }
           break;

       case 3:


           cout << "\n";
           cout << "Enter the base of the Triangle: ";
           cin >> base;
           cout << "Enter the height of the Triangle: ";
           cin >> height;

           if (base > 0 && height > 0)
           {
               Area = 0.5 * base * height;

               cout << "\n";
               cout << "Area of the Triangle is: " << Area << endl;
           }
           else
           {
               cout << "\nOnly enter positive values for base and height.";
           }
           break;

       case 4:

           cout << "Exiting Geometry Calculator\nGoodbye!\n";
           break;

       default: cout << "Sorry, that was an invalid entry!\nPlease re-run the program and "
           << "enter a valid menu choice.\n";
}
return 0;
}

In: Computer Science

(a) Provide a detailed explanation of the (signed) integer overflow. (b) Write C++ program that displays...

(a) Provide a detailed explanation of the (signed) integer overflow. (b) Write C++ program that displays the table of function 2n . This is an integer value that you must compute using multiplication, and the use of power function pow(2.,n ) is not permitted. Display lines that contain n and 2n for n=0,1,2,3,… and show all lines that contain correct values. Stop displaying before the occurrence of the integer overflow. Your program must work on any computer and for any size of integers; so, do not try to assume some specific word size. You have to detect the overflow and prevent that it creates wrong results.

In: Computer Science

I am running this code using C to count the words in char array, but somehow...

I am running this code using C to count the words in char array, but somehow it keeps counting the total characters + 1.

Any solution to fix this problem?

#include <stdio.h>

int main()
{
   char input[1001];
   int count =0;

   fgets(input, 1001, stdin);
   char *array = input;
   while(*array != '\0')   
   {
       if(*array == ' '){
           array++;
       }
       else{
       count++;
       array++;
       }
      
   }
   printf("this character's length is %d.", count);
   printf("this characterarray : %s", input);
  

   return 0;
}

In: Computer Science

Active directory (AD) is arguably the most critical component of Windows Server 2008, certainly for larger...

Active directory (AD) is arguably the most critical component of Windows Server 2008, certainly for larger organizations. It enables corporations to manage and secure their resources from a single directory service and with a common interface—a very powerful tool. Because it is so powerful and offers so many features and capabilities, it sometimes can be complex to those looking at it for the first time. This week, we are going to learn about AD in detail, starting with the fundamentals. As we progress during the week, you will begin to see it's not that intimidating after all. First, though, let's get the fundamentals down. What exactly is a directory service, and what are some examples in industry? Next, let's get the definition of active directory down—what exactly is it, and what benefits does it provide? After this, we'll look at the details on how it is implemented in the business environment.

What is a directory service?

What are some examples of a directory service?

What is the definition of AD?

What are the benefits of AD?

How is AD implemented in a business environment?

In: Computer Science

Overview: You will write a program that reads up to 100 numbers from a file. As...

Overview: You will write a program that reads up to 100 numbers from a file. As you read the
numbers, insert them into an array in ascending order.
Specifics:
1A. Write a function called insertIntoSortedArray .
i. It should take three arguments -
a. myArray[ ] : sorted array that should be able to hold at most 100 integers.
b. numEntries : the number of elements inserted so far.
c. newValue : the incoming value to be inserted into the sorted array (i.e.
myArray[]).
ii. The insertIntoSortedArray function should return a count of the elements inserted so
far (i.e. the current size of the array)
This function is defined as follows:
int insertIntoSortedArray ( int myArray[], int numEntries, int newValue);

In: Computer Science

write me a java progrm that does this: y=x^3 +1 drivative of y=3X^2+0 y=mx+b m is...

write me a java progrm that does this:

y=x^3 +1

drivative of y=3X^2+0

y=mx+b

m is slope for x=2 put 2 back to equation y=3(2)^2=12

now we have 12 and y=9 so

9=2(12)+b and we find b=-15

now we write new equation that with these information

y=12x-15 we solve for 12x-15=0, we solve for x and x=15/12=1.25

now we do the same thing above we put at the drivative equation y=3(1.25)^2+0=4.6875

now we put this to 2.943125=(4.6875)*3+b

we solve for b=-2.90625

y=4.6875x-2.90625 and 4.6875x-2.90625=0 we solve for x and =0.62 now we use this as we did above to find another new equation and this go in a loop to do the same thing over and over to find new point and equation

In: Computer Science

using java For this assignment, you will write a program that guesses a number chosen by...

using java

For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. When the program starts up, it outputs a prompt asking the user to choose a number from 1 to 10. It then proceeds to ask a series of questions requiring a yes or no answer. For example: Is your number evenly divisible by 3? (Yes or No).The user will enter “Yes” or “No” to each question. When the program is sure it knows the user’s number it outputs the number. For example, Your number is 9.

Your program must always guess the user’s number in less than five questions.

In: Computer Science

Briefly explain what are the chief differences between queues, dequeues and priority queue? How can you...

Briefly explain what are the chief differences between queues, dequeues and priority queue? How can you determine when it is appropriate to use a queue, a dequeue, or a priority queue? Write a simple example program using any of the 3.

In: Computer Science

Add comments to the following code: PeopleQueue.java import java.util.*; public class PeopleQueue {     public static...

Add comments to the following code:

PeopleQueue.java

import java.util.*;
public class PeopleQueue {

    public static void main(String[] args) {
        PriorityQueue<Person> peopleQueue = new PriorityQueue<>();
        Scanner s = new Scanner(System.in);
        String firstNameIn;
        String lastNameIn;
        int ageIn = 0;
        int count = 1;
        boolean done = false;

        System.out.println("Enter the first name, last name and age of 5 people.");
        while(peopleQueue.size() < 5) {
            System.out.println("Enter a person");
            System.out.print("First Name: ");
            firstNameIn = s.nextLine();
            System.out.print("Last Name: ");
            lastNameIn = s.nextLine();
            System.out.print("Age: ");
            while(!done) {
                try {
                    ageIn = Integer.parseInt(s.nextLine());
                    done = true;
                } catch (NumberFormatException e) {
                    System.out.println("Error: Please enter a number for age");
                    System.out.print("Age: ");
                }
            }
            Person person = new Person(firstNameIn, lastNameIn, ageIn);
            peopleQueue.add(person);
            System.out.println("Added to queue: " + firstNameIn + " " + lastNameIn + ", Age: " + ageIn + "\n");
            done = false;
        }

        NameCompare nameCompare = new NameCompare();
        List<Person> people = new ArrayList(peopleQueue);
        Collections.sort(people, nameCompare);

        System.out.println("Sorted by Last Name\n");
        for (int i = 0; i < people.size(); i++) {
            System.out.println("Name: " + people.get(i).getFirstName() + " "
                                        + people.get(i).getLastName() + ", Age: "
                                        + people.get(i).getAge());
        }


        System.out.println("\nSorted by Age and removed from queue\n");
        while (!peopleQueue.isEmpty()) {
            System.out.println("Removed Person " + count + " -" + peopleQueue.remove());
            count++;
        }
    }
}


Person.java

public class Person implements Comparable<Person> {

    private int age;
    private String firstName;
    private String lastName;

    public Person(String first, String last, int theirAge) {
        this.firstName = first;
        this.lastName = last;
        this.age = theirAge;
    }

    public String getFirstName() {
        return this.firstName;
    }

    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String last) {
        this.lastName = last;
    }

    public int getAge() {
        return this.age;
    }

    @Override
    public int compareTo(Person person) {
        if(this.equals(person))
            return 0;
        else if(getAge() < person.getAge())
            return 1;
        else
            return -1;
    }

    public String toString() {
        return " Name: " + getFirstName() + " " + getLastName() + ", Age: " + getAge();
    }


}


NameCompare.java

import java.util.Comparator;
public class NameCompare implements Comparator<Person> {

    public int compare(Person p1, Person p2) {
        int i = p1.getLastName().compareTo(p2.getLastName());
        if(i != 0) return -i;
        return i;
    }
}

In: Computer Science

how can you count the number of different letters there are in a word in C...

how can you count the number of different letters there are in a word in C programming?

In: Computer Science

Computer/Network Security How do you implement write access through web server?

Computer/Network Security

How do you implement write access through web server?

In: Computer Science

Based on what you have learned on the WAN technologies, there are three different types of...

  • Based on what you have learned on the WAN technologies, there are three different types of environments that need your help. The three types of environments include a small business, a medium corporate, and a large enterprise environment. What type of technology would you recommend for these different types of companies? Justify your answer.

  • What network optimization tools, methods, or techniques do you think will be most important to you as you manage your organization's network? Explain why?

In: Computer Science

PRELAB - Week of September 16 You’ve created a general-purpose function for allocating an array with...

PRELAB - Week of September 16

You’ve created a general-purpose function for allocating an array with elements of any data type:

array = createArray(numElems, elemSize);

and which supports the following function for obtaining its number of elements:

size = getArraySize(array);

and that’s all you’ll need for this pre-lab. All you’re asked to do for next week is to be able to:

1. Open a file

2. Read an integer giving the number of employee records in the file

3. Allocate an array of employee records (structs) to hold the records in the file

4. Read the records into the allocated array where an employee record is declared as:

typedef struct {

intempID, ssn, position;

float salary;}

Record;

To get comfortable with structs you’ll probably want to loop through the array and print the four members of each record–but you’d probably do that anyway just to verify that you get the results you expect from your test file!

In: Computer Science