Questions
Given a stack S and an element x, write a recursive algorithm that returns True if...

Given a stack S and an element x, write a recursive algorithm that returns True if x is in S, or False otherwise. Note that your algorithm should not change the content in S. What is the time complexity of your algorithm?

In: Computer Science

Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to...

Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 30, 40}, then newScores = {20, 30, 40, 10}.

--------------Code Below-----------

#include <iostream>
using namespace std;

int main() {
const int SCORES_SIZE = 4;
int oldScores[SCORES_SIZE];
int newScores[SCORES_SIZE];
int i;

for (i = 0; i < SCORES_SIZE; ++i) {
cin >> oldScores[i];
}

/* Your solution goes here */

for (i = 0; i < SCORES_SIZE; ++i) {
cout << newScores[i] << " ";
}
cout << endl;

return 0;
}

In: Computer Science

Given a positive integer n, write a recursive algorithm that returns the number of the digits...

Given a positive integer n, write a recursive algorithm that returns the number of the digits in n. For example, if the given number n is 12345, the algorithm should return 5. What is the time complexity of your algorithm?

In: Computer Science

Fill in the code only using pointer variables #include using namespace std; int main() { int...

Fill in the code only using pointer variables

#include

using namespace

std; int main() {

int longside; // holds longside (length)

int wideside; // holds wideside(width)

int total; // holds total (area)

int *longsidePointer = nullpointer; // int pointer which will be set to point to length

int *widthPointer = nullpointer; // int pointer which will be set to point to width

cout << "Please input the longside of the rectangle" << endl;

cin >> longside;

cout << "Please input the wideside of the rectangle" << endl;

cin >> wideside;

// Fill in code to make longsidePointer point to longside(length) (hold its address)

// Fill in code to make widesidePointer point to wideside(width) (hold its address)

total = // Fill in code to find the total(area) by using only the pointer variables

cout << "The total is " << total << endl;

if (// Fill in the condition longside(length) > wideside(width) by using only the pointer variables)

cout << "The longside is greater than the wideside" << endl;

else if (// Fill in the condition of wideside(width) > longside(length) by using only the pointer variables)

cout << "The wideside is greater than the longside" << endl;

else

cout << "The wideside and longside are the same" << endl;

return 0;

}

}

In: Computer Science

The user will input a dollar amount as a floating point number; read it from input...

The user will input a dollar amount as a floating point number; read it from input using a Scanner and the .nextDouble() method. Convert the number of dollars into a number of whole (integer) cents, e.g., $1.29 = 129 cents. Determine and output the optimal number of quarters, dimes, nickels, and pennies used to make that number of cents.

Ex: if the input is

1.18

The output should be

4
1
1
3

for 4 quarters, 1 dime, 1 nickel, 3 pennies.

Hints

  1. Remember that a double multiplied by an int gives back a double. You will need to cast the result to int if you want to do integer arithmetic, like modulo.
  2. % is modulo.
  3. There is no "f-string" equivalent in Java.

(STARTING CODE)

import java.util.Scanner;

public class Change {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

/* Type your code here. */
}
}

In: Computer Science

Given a stack S and an element x, write a recursive algorithm that returns True if...

Given a stack S and an element x, write a recursive algorithm that returns True if x is in S, or False otherwise. Note that your algorithm should not change the content in S. What is the time complexity of your algorithm?

In: Computer Science

I ALREADY HAVE THE CORRECT ANSWERS. CAN YOU EXPLAIN TO ME HOW AND/OR WHY THESE ARE...

I ALREADY HAVE THE CORRECT ANSWERS. CAN YOU EXPLAIN TO ME HOW AND/OR WHY THESE ARE THE ANSWERS? THANK YOU :)

int a(int &x, int y) { x = y; y = x + 1; return y;

}

int b(int &x, int y) { y = x + 1; x = y; return y;

}

void c(int x, int y) { if (x > 2) return; cout << y; c(x + 1, y - 1);

}

int main() {

int x[2][3] = {{1, 2, 3}, {4, 5, 6}};

int y[3] = {7, 8, 9};

cout << x[1][1] << endl;   // line (a)

y[0] = a(y[0], y[1]);

cout << y[0] << y[1] << endl; // line (b)

cout << b(x[0][2], x[1][2]) << endl;    // line (c)

cout << x[0][2] << x[1][2] << endl; // line (d)

c(0, 4); cout << endl; // line (e)

}

(a) What is the output from the instruction beginning on line (a)?

Answer: 5

(b) What is the output from the instruction beginning on line (b)?

Answer: 98

(c) What is the output from the instruction beginning on line (c)?

Answer: 4

(d) What is the output from the instruction beginning on line (d)?

Answer: 46

(e) What is the output from the instruction beginning on line (e)?

Answer: 432

In: Computer Science

Refactor Assignment 1 into 3 project related files. Customer.h - Class Specification Customer.cpp - Class Implementation...

Refactor Assignment 1 into 3 project related files.

Customer.h            - Class Specification
Customer.cpp         - Class Implementation (Methods)

TestCustomer.cpp - Your code that performs the logic from Assignment 1.

The 3 files need to be named as listed above and should compile without errors.

I am not understanding how to do this.

Below is the code:

#include
#include

using namespace std;

const int NAME_SIZE = 20;
const int STREET_SIZE = 30;
const int CITY_SIZE = 20;
const int STATE_CODE_SIZE = 3;

class Customer
{
private:
   long customerNumber;

   char name[NAME_SIZE];
   char streetAddress_1[STREET_SIZE];
   char streetAddress_2[STREET_SIZE];
   char city[CITY_SIZE];
   char state[STATE_CODE_SIZE];

   int zipCode;

public:
   void setNumber(long number);

   bool setName(char name[]);
   bool setStreetAddress1(char street1[]);
   bool setStreetAddress2(char street2[]);
   bool setCity(char c[]);
   bool setState(char st[]);
   bool setZipCode(int zip);

   long getNumber();

   char* getName();
   char* getStreetAddress1();
   char* getStreetAddress2();
   char* getCity();
   char* getState();

   int getZipCode();
};


void Customer::setNumber(long number)
{
   customerNumber = number;
}

bool Customer::setName(char n[])
{
  
   if (strlen(n) > 0)
   {
       strcpy(name, n);
       return true;
   }

   return false;
}

bool Customer::setStreetAddress1(char street1[])
{

   if (strlen(street1) > 0)
   {
       strcpy(streetAddress_1, street1);
       return true;
   }

   return false;
}

bool Customer::setStreetAddress2(char street2[])
{
   if (strlen(street2) > 0)
   {
       strcpy(streetAddress_2, street2);
       return true;
   }

   return false;
}


bool Customer::setState(char st[])
{
  
   if (strlen(st) > 0)
   {
       strcpy(state, st);
      
       for (int i = 0; i < strlen(state); i++)
       {
           state[i] = toupper(state[i]);
           if (state[i] < 'A' || state[i] > 'Z')
               return false;
       }

       return true;
   }

   return false;
}

bool Customer::setCity(char c[])
{

   if (strlen(c) > 0)
   {
       strcpy(city, c);

       for (int i = 0; i < strlen(city); i++)
       {          
           city[i] = toupper(city[i]);
           if (city[i] < 'A' || city[i] > 'Z')
               return false;
       }

       return true;
   }

   return false;

}

bool Customer::setZipCode(int zip)
{

   if (zip >= 0 && zip <= 99999)
   {
       zipCode = zip;
       return true;
   }

   return false;
}


long Customer::getNumber()
{
   return customerNumber;
}

char* Customer::getName()
{
   return name;
}

char* Customer::getStreetAddress1()
{
   return streetAddress_1;
}

char* Customer::getStreetAddress2()
{
   return streetAddress_2;
}

char* Customer::getState()
{
   return state;
}

char* Customer::getCity()
{
   return city;
}

int Customer::getZipCode()
{
   return zipCode;
}

int main()
{
   Customer info;
  

   char name[NAME_SIZE];
   char streetAddress_1[STREET_SIZE];
   char streetAddress_2[STREET_SIZE];
   char city[CITY_SIZE];
   char state[STATE_CODE_SIZE];
   int zipCode;

   info.setNumber(1);

   do
   {
       cout << "What is your name: ";
       cin.getline(name, NAME_SIZE);
   } while (!info.setName(name));


   do
   {
       cout << "Street you live on: ";
       cin.getline(streetAddress_1, STREET_SIZE);
   } while (!info.setStreetAddress1(streetAddress_1));


   do
   {
       cout << "Second street(if applicable, type N/A if not): ";
       cin.getline(streetAddress_2, STREET_SIZE);
   } while (!info.setStreetAddress2(streetAddress_2));

   do
   {
       cout << "What state do you live in: ";
       cin.getline(state, STATE_CODE_SIZE);
   } while (!info.setState(state));

   do
   {
       cout << "What City do you live in: ";
       cin.getline(city, CITY_SIZE);
   } while (!info.setCity(city));

   do
   {
       cout << "what is the zip code: ";
       cin >> zipCode;
   } while (!info.setZipCode(zipCode));


  
   cout << "\n" << "Details of Customer: " << "\n";
   cout << "Customer Number: " << info.getNumber() << "\n";
   cout << "Name: " << info.getName() << "\n";
   cout << "Street Address 1: " << info.getStreetAddress1() << "\n";
   cout << "Street Address 2: " << info.getStreetAddress2() << "\n";
   cout << "State: " << info.getState() << "\n";
   cout << "City: " << info.getCity() << "\n";
   cout << "Zip code: " << info.getZipCode() << "\n";

   return 0;
}

In: Computer Science

How an isolated workspace is provided by docker to keep applications on the same host or...

How an isolated workspace is provided by docker to keep applications on the same host or cluster isolated from one another? Give a proper answer.

In: Computer Science

Question 1 (20pts): Create a dictionary of the form {“Jordan”: “Basketball”, “Federer”: “Tennis”, “Ronaldo”: “Football”} and...

Question 1 (20pts):

Create a dictionary of the form {“Jordan”: “Basketball”, “Federer”: “Tennis”, “Ronaldo”: “Football”} and perform the following actions

  • Print all the keys in the dictionary
  • Print all the values in the dictionary
  • Iterate through the dictionary and print the value only if the key is “Federer”
  • Iterate through the dictionary and print the key only if the value is “Football”

Question 2 (15pts):

List1 = [3, 4, 5, 20, 5]

List2 = [4, 9, 6, 2, 10].

Using list comprehensions, print the output if you multiply the i-th element of each list

Question 3 (15pts):¶

Dic1 = {"John":10, "Joe":15}

  • Check whether “John” is one of the keys
  • Remove the key “Joe” along with its associated value
  • Add another key and value pair - “Jean”: 40

Question 4 (15pts):

  • Write a user defined function to find the highest of the three numbers: 30, 10 and 20. The highest number should be printed. Note: The function has to be user defined.

  • With a given integral number n, write a program to generate a dictionary that contains key value pairs such as i: 2^i, and i takes values between 1 and n (both included). Then print the dictionary.

Suppose the following input is supplied to the program:

4

Then, the output should be:

{1: 2, 2: 4, 3: 8, 4: 16}

Question 5 (20pts):

  • Using list comprehensions, print all the values between 1 and 10 that are divisible by 2. The output should be [2, 4, 6, 8].

  • By using list comprehension, please write a program to print the list after removing the value 24 in [12,24,35,24,88,120,155].

Question 6 (15pts):

Remove the last value in [12,24,35,24,88,120,155] consecutively and print the removed value in each removal.

In: Computer Science

using java Design a class named Triangle that extends GeometricObject. The class contains: • Three double...

using java Design a class named Triangle that extends GeometricObject. The class contains: • Three double data fields named side1, side2, and side3 to denote three sides of a triangle. • A no-arg constructor that creates a default triangle with default values 1.0. • A constructor that creates a triangle with the specified side1, side2, and side3. In a triangle, the sum of any two sides is greater than the other side. The Triangle class must adhere to this rule and throw an IllegalTriangleException object if a triangle is created with sides that violate the rule • The accessor methods for all three data fields. • A method named getArea() that returns the area of this triangle. • A method named getPerimeter() that returns the perimeter of this triangle. • A method named toString() that returns a string description for the triangle. Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input. The program should display the area, perimeter, color, and true or false to indicate whether it is filled or not.

In: Computer Science

Rectangle Class in C++ Create a Rectangle class that has two data members: length_ and width_....

Rectangle Class in C++

Create a Rectangle class that has two data members: length_ and width_. Create the corresponding accessor and mutator functions to access and change both data members.

Create a member function area that returns the area of the Rectangle object. Finally, create a function longest_rectangle that accepts two Rectangle objects as parameters and returns the Rectangle object with the longer length.

Write the Rectangle class and the longest_rectangle function prototype in rectangle.hpp. Take note that longest_rectangle is not a member function of the Rectangle class. Provide the function's implementation in rectangle.cpp.

Complete main.cpp according to the comments provided in the file.

Sample Output:

Rectangle 1
Please enter the length: 2
Please enter the width: 3
Rectangle 1 created with length 2 and width 3
The area of Rectangle 1 is: 6

Rectangle 2
Please enter the length: 4
Please enter the width: 5
Rectangle 2 created with length 4 and width 5
The area of Rectangle 2 is: 20

The longest rectangle has a length of 4, a width of 5, and an area of 20.

Submission checklist

  1. Created function prototype and stored in .hpp file.
  2. Created function implementation and stored in .cpp file (see reference).
  3. Call function in the driver
  4. Compiled and ran the driver (main).
  5. Manually checked for compilation and logical errors.
  6. Ensured no errors on the unit test (make test).
  7. Followed advice from the stylechecker (make stylecheck).
  8. Followed advice from the formatchecker to improve code readbility (make formatcheck).

In: Computer Science

Write a java application that will read a set of values from the user and stores...

Write a java application that will read a set of values from the user and stores them in array a[]. The application should ask the user for the number of values he will enter. You need to do the following methods: 1. Read: This method will read n values from the user and store them in an array a 2. Print: this method will print the array as given in the sample output 3. maxEven: This method will find the maximum value of the even numbers 4. DrawSquarec: this method will draw a square using the elements of the array (see sample) Sample Output How many elements you have:5 Enter the elements: 10 1 4 5 6 The array is: 10 1 4 5 6 The maximum even number is 10 10 10 10 10 10
11111
44444

55555

66666

In: Computer Science

Objective: Only attempt this assignment after thoroughly reading Chapter 4 of the Visual Basic text. The...

Objective: Only attempt this assignment after thoroughly reading Chapter 4 of the Visual Basic text. The objective of the assignment is to write a program in Visual Basic that applies decision logic within the program. Another objective is to work through any syntax errors encountered (debugging) to develop a correct solution that is free of errors.

Description: Create a working Visual Basic solution using the Visual Studio IDE that accepts two numbers from the user and displays one of the following messages: First is larger, Second is larger, Numbers are equal. Provided your logic from last week was correct, you can use the pseudocode and flowchart from last's week's assignment to help you code your solution. After you output one of the three messages, calculate the average of the 2 numbers and display it for the user.

Requirements: For full credit, make sure that you create your program using Visual Studio. Also make sure that the program compiles (builds) successfully and without any errors. To test the logic of your program, make sure to try many different combinations of numbers. Ensure that in addition to displaying one of the three messages to the user that you also calculate and display the average as described.

In: Computer Science

Scenario The instructors at the community college are happy with your grade averaging program and want...

Scenario

The instructors at the community college are happy with your grade averaging program and want to

expand it. You have been asked by the community college to modify the existing program to include

additional functionality that will calculate a student’s final grade for the faculty for multiple students.

The new program will accept data from the instructors, calculate the final grade and display information

on the screen. The program will output student information, the student category averages, the final

numeric grade and a statement that indicates if the student is passing.

Part I

1. Code the program using Java. The program should incorporate greetings to the instructor as well as

an ending message.

2. The program should include two classes: Grades.java and GradeCalculator.java.

3. The GradeCalculator.java class should include the main method and instantiate two objects

representative of two different sets of student grades. It should get input from the user and call

mutator and accessor methods to set and get object values.

4. The Grades.java class should include a constructor which will

a. initialize the Lab, Test and Project averages to a value of zero (0) and the final exm grade

to a value of zero (0) for each student grade object

b. keeps a running count of the number of students entered.

c. Records the system date the grades were entered for each student (Hint: use LocalDate class).

5. The program should greet the user by calling a method named displayGreeting();

6. The program should request the following information from the user:

Input Data (for each student):

  • Student First Name (on a separate line from last name)
  • Student Last Name(on a separate line from first name)
  • Student ID
  • Lab Average
  • Project Average
  • Test Average
  • Final exm grade

7. The program should output the following information to the instructor by calling a method named

displayGrades() for each student:

Instructor receives the following output for each set of grades (one set for each student):

  • Student’s first and last name concatenated on one line (i.e. John Smith)
  • Student ID on a separate line
  • List the average for each type of grade category (make sure the output is professional and is aligned appropriately and displays decimal points).

Example: (these are example values and should be output for both students)

Test Avg: 93.5

Lab Avg: 100

Project Avg: 93

Final Exm: 95

Course Grade: xx (weighted average calculated by the program)

  • The numeric course grade is calculated based on a weighted average:

Labs = 30%

Tests = 30%

Projects = 30%

Final Exm = 10%

Final Grade = 30% x lab average + 30% x test average + 30% x project

average + 10% x final exm

  • A message indicating whether the student is passing (true or false) – DO NOT use an IF

statement. Use the Boolean variable in a logical expression and print the result. Assume a 10

point scale when determining the passing rate.

  • Thank the instructor for accessing the program at the end of the program

8. Name the java class files Grades.java and GradeCalculator.java.

a. The GradeCalculator should include the main( ) method which instantiates objects, calls

methods to enter grades, get and set grades entered and displays information to the

instructor for each student.

b. The Grades class should include a constructor and methods to set and get values.

c. The calculations can be included in either the Grades or the GradeCalculator class. This can

be your decision.

In: Computer Science