Questions
1. Write a C++ program, for.cpp, that reads three integers. The first two specify a range,...

1. Write a C++ program, for.cpp, that reads three integers. The first two specify a range, call them bottom and top, and the other gives a step value. The program should print four sequences using for loops:

  • Each value in the range from bottom to top

  • Each value in the range from top to bottom, reverse counting

  • Every second value in the range from bottom to top

  • Every value from bottom to top increasing by step

    a: If bottom is less than top when entered, the program will exchange the two values.
    b: If step is negative, the program will be set to its absolute value (positive equivalent).

    Sample Run 1 (should have same text and spacing as in examples):

    Enter the bottom value in the range: 3
    Enter the top value in the range: 20
    Enter the step value: 6
    

    Values from 3 to 20:
    3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

    Values from 20 to 3:
    20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3

    Every second value from 3 to 20:
    3 5 7 9 11 13 15 17 19
    
    Every 6th value from 3 to 20:
    3 9 15
    

Sample Run 2 (demonstrating part a and b):

Enter the bottom value in the range: 72 Enter the top value in the range: 56 Enter the step value: -4

Values from 56 to 72:
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

Values from 72 to 56:
72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56

Every second value from 56 to 72:
56 58 60 62 64 66 68 70 72
Every 4th value from 56 to 72:
56 60 64 68 72

In: Computer Science

Write a C++ program, falling.cpp, that inputs a distance in meters from the user and computes...

Write a C++ program, falling.cpp, that inputs a distance in meters from the user and computes the amount of time for the object falling from that distance to hit the ground and the velocity of the object just before impact. Air resistance is discounted (assumed to fall in a vacuum).

To compute the time, use the formula: t = Square Root (2d / g)

where d is the distance in meters and g is the acceleration due to gravity on earth (use 9.807 meters/sec2). The time is measured in seconds.

To compute the velocity, use the formula:
v = Square Root (2dg)
The velocity is measured in meters per second.

You are required to write the following functions:

// Computes the amount of time for an object to fall to the // ground given the distance to fall as a parameter. The // time is returned (computeTime does not print anything). double computeTime (double distance);

// Computes the final velocity of an object falling to the // ground given the distance to fall as a parameter. The // velocity is returned (computeVelocity does not print // anything).

double computeVelocity (double distance);

// print prints its three parameters with labels.
// Print does not return a value.
void print (double distance, double time, double velocity);

Sample run:

Enter the distance: 100

Distance: 100.00 meters Time: 4.52 seconds
Velocity: 44.29 meters/second

Double values should be printed with two digits after the decimal.

In: Computer Science

Q2. The 9’s complement of a decimal digit d (0 to 9) is defined to be...

Q2. The 9’s complement of a decimal digit d (0 to 9) is defined to be 9 - d. A logic circuit produces the 9’s complement of an input digit where the input and output digits are represented in BCD. Label the inputs A, B, C, and D, and label the outputs W, X, Y and Z. (a) Determine the minterms and don’t-care minterms for each of the outputs. (b) Determine the maxterms and don’t-care maxterms for each of the outputs. ***Please kindly note, questions are solved as chapter 4

In: Computer Science

Write a loan amortization program in C++. Assume the loan is paid off in equal monthly...

Write a loan amortization program in C++. Assume the loan is paid off in equal monthly installments. To compute the monthly payment you must know: 1.the initial loan value 2. # of months the loan is in effect 3. APR. You should prompt the user for each of these 3 things then compute the monthly payment. The following formula is useful: Payment = (factor * value * monthly_rate) / (factor - 1) where factor = (1 + monthly_rate) ^ number_of_months. Then set up the amortization table that will show for each month the starting balance, the interest paid, the payment amount and the new balance. Use comments in the program and use a function that compute_payment given 3 values of loan amount, APR, and loan length. Most variables in the program should be doubles. The output should have headers for each column, echo the input values, and must be aligned.

In: Computer Science

Create a program named MergeSort.java then copy the following code to your program: public static void...

  1. Create a program named MergeSort.java then copy the following code to your program:
    • public static void mergeSort(int[] arr){
         mergeSortRec(arr, 0, arr.length-1);
      }
      private static void mergeSortRec(int[] arr, int first, int last){
         if(first<last){
          int mid=(first+last)/2;
      mergeSortRec(arr, first, mid);
          mergeSortRec(arr, mid+1,last);
          merge(arr, first, mid, mid+1, last);
         }
      }
      private static void merge(int[] arr, int leftFirst,
         int leftLast, int rightFirst, int rightLast){
         int[] aux=new int[arr.length];
         //extra space, this is downside of this algorithm
         int index=leftFirst;
         int saveFirst=leftFirst;
         while(leftFirst<=leftLast && rightFirst <=rightLast){
      if(arr[leftFirst]<=arr[rightFirst]){
         aux[index++]=arr[leftFirst++];
          }else{
         aux[index++]=arr[rightFirst++];
          }
         }
         while(leftFirst<=leftLast){
          aux[index++]=arr[leftFirst++];
         }
         while(rightFirst<=rightLast)
          aux[index++]=arr[rightFirst++];
         for(index=saveFirst; index<=rightLast; index++)
          arr[index]=aux[index];
      }
  2. Write a main method that accepts three numbers N, A, B (assume A<B) from the command argument list, then use the number N to create an N-element int array.
  3. Assign random numbers between [A, B] to each of the N elements of the array.
  4. Call mergeSort method to sort the array.
  5. Write instructions to record the time spent on sorting.
  6. (Optional) you may write code to verify the array was sorted successfully.
  7. Once completed, test your program with different numbers N, A, B and screenshot your result. Your result should include the number of elements and sorting time.
  8. Please include the following in the Word document you created for the assignment for the final submission:  
    • Copy/paste your completed code in MergeSort.java
    • Insert at least one screenshot of the running output in #7 above
    • Answer this question: What is the average Big O for this sort?

In: Computer Science

Provide a formatted printing statement that yields $▯▯323.500 for input 323.5. Note that ▯ means a...

Provide a formatted printing statement that yields $▯▯323.500 for input 323.5. Note that ▯ means a space.

In: Computer Science

Write a code to initialize a 2D array with random integers (not has to be different)....

Write a code to initialize a 2D array with random integers (not has to be different). Write a function to count the number of cells that contain an even number within the 2D array.

C++

In: Computer Science

The monthly payment for a given loan pays the principal and the interest. The monthly interest...

The monthly payment for a given loan pays the principal and the interest. The monthly interest is computed by multiplying the monthly interest rate and the balance (the remaining principal). The principal paid for the month is therefore the monthly payment minus the monthly interest. Write a pseudocode and a Python program that let the user enter the loan amount, number of years, and interest rate, and then displays the amortization schedule for the loan (payment#, interest, principal, balance, monthly payment). Hint: use pow function (example, pow (2, 3) is 8. Same as 2 **3. ); monthly payment is the same for each month, and is computed before the loop.

In: Computer Science

Binary files are convenient to computers because they’re easily machine readable. Text files are human readable,...

Binary files are convenient to computers because they’re easily machine readable. Text files are human readable, but require parsing and conversion to process in the computer. Consider a class Person that has the following structure:

public class Student {
    private String name;
    private int age;
    private double gpa;

    public Student() {
    }

    public Student(String name, int age, double gpa) {
        this.name = name;
        this.age = age;
        this.gpa = gpa;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

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

    public void setAge(int age) {
        this.age = age;
    }

    public double getGpa() {
        return this.gpa;
    }

    public void setGpa(double gpa) {
        this.gpa = gpa;
    }

    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Student{");
        builder.append(String.format("%s=%s", "name", name));
        builder.append(String.format(",%s=%d", "age", age));
        builder.append(String.format(",%s=%.2f", "gpa", gpa));
        builder.append("}");
        return builder.toString();
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof Student) {
            return equals((Student)obj);
        }
        return false;
    }
    
    public boolean equals(Student other) {
        if (other == null) {
            return false;
        }
        return name.equals(other.name) &&
            age == other.age &&
            Math.abs(gpa - other.gpa) < 0.0001;
    }
}

A number of student records were written out to a file using the toString() method given above. Roughly, they look like the following:

Student{name=Joe O'Sullivan,age=22,gpa=3.14}
Student(name=Jane Robinson,age=19,gpa=3.81}
....
Student{name=Jill Gall,age=21,gpa=2.98}

Your task is to implement a method that will return an array of Students based on a parameter file name that is passed into the method. You will open the text file, read lines, split lines into fields, and then call the setters based on the key/value pairs in the string. Fields will always be in the same order: name, age, gpa. The array should be exactly the same size as the number of lines in the file you are reading. At most, there will be 20 lines in the file. You should not throw any exceptions from the function. if the file doesn't exist, return a zero-length array.

Some hints:

  • You can use the File class to connect the name to the file on disk.
  • You can create a Scanner object by passing in the File to read lines.
  • You can use the split() method of String to take a line from the file and break it up based on delimiters You may need to do this multiple times (e.g. once on a comma, and then on an equals sign).
  • To convert from string data to integer data, use Integer.parseInt(). You can do the same with doubles and Double.parseDouble()

In: Computer Science

Discuss the stability of QuickSort and Heapsort. Algorithm coures

  1. Discuss the stability of QuickSort and Heapsort.

Algorithm coures

In: Computer Science

In C create a program that stores contact info. The program must have the following features:...

In C create a program that stores contact info. The program must have the following features:

  • Able to store First Name, Phone Number and Birthday (MM/DD/YYYY)
  • Able to search for a specific contact using First Name, Phone Number and Birthday (find)
  • Able to delete a specific contact using First Name, Phone Number and Birthday (delete)
  • Print entire contact list
  • Show number of entries in contact list
  • Able to save Contact List to file (save)
  • Able to load Contact List from file (load)
  • Able to exit program (exit/quit)

The program must have the following structure:

  • Makefile that completely builds the entire project
  • Main file and library (implementation and header files with header guards)
  • Neat and Tidy code
  • Must have meaningful comments
  • Program must have a command and argument structure
  • Must use a linked list or dynamic array for contact list (NO REGULAR ARRAYS)
  • NO GLOBAL VARIABLES
  • Must use dynamically allocated memory that is correctly managed
  • Must use pointers
  • Must use a decision structure
  • Must give user feedback for all input (“contact list saved”, “entry ‘<user input>’ deleted”, etc.)
  • Must keep contact list sorted by First Name (sort as a new entry is added)
  • Use binary searching algorithm to find entries in contact list
  • All program features must be implemented as a function in a library.

Extra credit:

  • Used meaningful typedefs
  • Used enumerated data types
  • Used conditional operator in an inline if
  • Ask user to save contact list if they haven’t already before exiting

In: Computer Science

AES128 encryption given by the following setting (Note: plaintext, Cipherkey and Ciphertext are Bytes) a. Plaintext:...

AES128 encryption given by the following setting (Note: plaintext, Cipherkey and Ciphertext are Bytes)

a. Plaintext: 00……00 Cipherkey: 00……00 Ciphertext: 66 E9 4B D4 EF 8A 2C 3B 88 4C FA 59 CA 34 2B 2E

b. Plaintext: 00……01 Cipherkey: 00……00 Ciphertext: 58 E2 FC CE FA 7E 30 61 36 7F 1D 57 A4 E7 45 5A

c. Plaintext: 00……00 Cipherkey: 00……01 Ciphertext: 05 45 AA D5 6D A2 A9 7C 36 63 D1 43 2A 3D 1C 84

Please compare the result of the ciphertext from the above questions, and explain what are the difference.

In: Computer Science

You will use your previous programming project as a starting point. Be sure to copy and...

You will use your previous programming project as a starting point. Be sure to copy and rename your file from that project and edit the internal documentation to reflect the new name and date.

Use your previous working Java program as a starting point (Project 3). Create another function that determines whether the customer should receive a discount. Assume your food truck gives a 10% discount on orders over $50 (the total BEFORE tax). If the order is eligible for a discount, then calculate and display the discount. If the order does not get a discount, then still display the discount, but it should be 0. Include a line before this that tells every customer that your business gives a 10% discount on all orders over $50 so they understand this part of their receipt.

And this was the project 3 to be used to write this program.

import java.util.Scanner;

public class Main

{

static double salesTax, amountDueWithTax, totalAmount, amountTendered, change;

static Scanner sc = new Scanner(System.in);

//get all the information about items ordered

public static int[] readData(String items[])

{

int num[] = new int[5];

for(int i=0; i<5; i++)

{

System.out.print("Enter quantity of " + items[i] + " : ");

//get all the information about items ordered and the amount of money tendered as mentioned in ques

num[i] = sc.nextInt();

}

return num;

}

//method to calculate amount with tax

public static void getAmountWithTax(int num[], double rate[], double amount[])

{

double totalAmount = 0;

//find the amount for all items and totalAmount

for(int i=0; i<5; i++)

{

amount[i] = num[i]*rate[i];

totalAmount = totalAmount + amount[i];

}

//find salesTax, amountDueWithTax

salesTax = totalAmount*0.06;

amountDueWithTax = totalAmount + salesTax;

}

//method to print the receipt

public static void printInfo(int num[], String items[], double rate[], double amount[])

{

System.out.println("Thank you for visiting Roronoa Pizza Place!"); //print the title and Address

System.out.println("109th Avenue, Mount Olympia");

System.out.println("Your Order Was");

for(int i=0; i<5; i++)

System.out.printf("%d %s @ %.4f each: $%.4f\n",num[i], items[i], rate[i] ,amount[i]);

System.out.printf("Amount due for pizzas and drinks is: $%.4f\n", totalAmount);

System.out.printf("Sales tax amount is: $%.4f\n", salesTax);

System.out.printf("Total amount due, including tax is: $%.4f\n", amountDueWithTax);

System.out.printf("Amount tendered: $%.3f\n", amountTendered);

System.out.printf("Change: $%.4f\n", change);

}

//main method

public static void main(String[] args)

{

double rate[] ={8.99, 1.5, 12.99, 2.5, 1.5};

double amount[] = new double[5];

String items[] = {"Small pizzas", "Small pizza toppings", "Large pizzas", "Large pizza toppings", "Soft Drinks" };

///get all the information about items ordered

int num[] = readData(items);

//calculate amountDueWithTax

getAmountWithTax(num, rate, amount);

do{

System.out.print("Enter Amount tendered : ");

amountTendered = sc.nextDouble();

if(amountTendered >= amountDueWithTax)

break;

System.out.println ("Money given is not enough!Try again");

}while(true);

//calculate the change

change = amountTendered - amountDueWithTax;

//print the receipt

printInfo(num, items, rate, amount);

}

}

In: Computer Science

Suppose we are sorting an array of eight integers using quicksort, and we have just finished...

Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the array looking like this: 2 5 1 7 9 12 11 10. What are the possible values of pivot?

Algorithm coures

In: Computer Science

C - programming problem: Let T be a sequence of an even length 2k, for some...

C - programming problem:

Let T be a sequence of an even length 2k, for some non-negative integer k. If its prefix of k symbols (or, the first k symbols in T) are the same as its suffix of k symbols (respectively, the last k symbols in T), then T is called a tandem sequence. For example, T[8] = 31103110 is a tandem sequence. Given a sequence S, if T is a subsequence of S and T is tandem, then T is called a tandem subsequence of S. One can then similarly define what a longest tandem subsequence (LTS for short) of S is.

Write a program that reads in two sequences with max length: 10,000, which computes, and prints the longest-tandem subsequence or LTS, and its length.

Sample program run:

Enter a sequence: 3110283025318292818318143

# an LTS (length = 10) for the sequence is:

1283312833

In: Computer Science