Questions
Please note that this problem have to use sstream library in c++ (1) Prompt the user...

Please note that this problem have to use sstream library in c++

(1) Prompt the user for a title for data. Output the title. (1 pt)

Ex:

Enter a title for the data:
Number of Novels Authored
You entered: Number of Novels Authored


(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)

Ex:

Enter the column 1 header:
Author name
You entered: Author name

Enter the column 2 header:
Number of novels
You entered: Number of novels


(3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they have finished entering data points. Output the data points. Store the string components of the data points in a vector of strings. Store the integer components of the data points in a vector of integers. (4 pts)

Ex:

Enter a data point (-1 to stop input):
Jane Austen, 6
Data string: Jane Austen
Data integer: 6


(4) Perform error checking for the data point entries. If any of the following errors occurs, output the appropriate error message and prompt again for a valid data point.

  • If entry has no comma
    • Output: Error: No comma in string. (1 pt)
  • If entry has more than one comma
    • Output: Error: Too many commas in input. (1 pt)
  • If entry after the comma is not an integer
    • Output: Error: Comma not followed by an integer. (2 pts)


Ex:

Enter a data point (-1 to stop input):
Ernest Hemingway 9
Error: No comma in string.

Enter a data point (-1 to stop input):
Ernest, Hemingway, 9
Error: Too many commas in input.

Enter a data point (-1 to stop input):
Ernest Hemingway, nine
Error: Comma not followed by an integer.

Enter a data point (-1 to stop input):
Ernest Hemingway, 9
Data string: Ernest Hemingway
Data integer: 9


(5) Output the information in a formatted table. The title is right justified with a setw() value of 33. Column 1 has a setw() value of 20. Column 2 has a setw() value of 23. (3 pts)

Ex:

        Number of Novels Authored
Author name         |       Number of novels
--------------------------------------------
Jane Austen         |                      6
Charles Dickens     |                     20
Ernest Hemingway    |                      9
Jack Kerouac        |                     22
F. Scott Fitzgerald |                      8
Mary Shelley        |                      7
Charlotte Bronte    |                      5
Mark Twain          |                     11
Agatha Christie     |                     73
Ian Flemming        |                     14
J.K. Rowling        |                     14
Stephen King        |                     54
Oscar Wilde         |                      1


(6) Output the information as a formatted histogram. Each name is right justified with a setw() value of 20. (4 pts)

Ex:

         Jane Austen ******
     Charles Dickens ********************
    Ernest Hemingway *********
        Jack Kerouac **********************
 F. Scott Fitzgerald ********
        Mary Shelley *******
    Charlotte Bronte *****
          Mark Twain ***********
     Agatha Christie *************************************************************************
        Ian Flemming **************
        J.K. Rowling **************
        Stephen King ******************************************************
         Oscar Wilde *

In: Computer Science

in javascript OR JAVA You are given two numbers n and m representing the dimensions of...

in javascript OR JAVA

You are given two numbers n and m representing the dimensions of an n × m rectangular board. The rows of the board are numbered from 1 to n, and the columns are numbered from 1 to m. Each cell has a value equal to the product of its row index and column index (both 1-based); in other words, board[i][j] = (i + 1) * (j + 1).

Initially, all the cells in the board are considered active, though some of them will eventually be deactivated through a sequence of queries - specifically, you will be given an array queries, where each query is of one of the following 3 types:

  • [0] - find the minimum value among all remaining active cells on the board.
  • [1, i] - deactivate all cells in row i;
  • [2, j] - deactivate all cells in column j;

Given the dimensions n, m, and the array of queries, your task is to return an array consisting of calculated values (results of the queries of the 0th type), in the order in which they were calculated.

In: Computer Science

1) Translate the following C program to Pep/9 assembly language. Please attach screenshot of Pep/9 simulator...

1) Translate the following C program to Pep/9 assembly language. Please attach screenshot of Pep/9 simulator running the program.

#include <stdio.h.>

int main() {

int numitms,j,data,sum;

scanf("%d", &numitms);

sum=0;

for (j=1;j<=numitms;j++) {

scanf("%d", &data);

sum+=data;

}

printf("sum: %d\n",sum);

return0;

}

In: Computer Science

why do you think people seek to go that route of becoming a script kiddie as...

why do you think people seek to go that route of becoming a script kiddie as opposed to actually following through with an education?

In: Computer Science

1, Create a class Car. The class has four instance fields: make (String - admissible values:...

1, Create a class Car. The class has four instance fields:

  • make (String - admissible values: Chevy, Ford, Toyota, Nissan, Hyundai)
  • size (String - admissible values: compact, intermediate, fullSized),
  • weight (int - admissible values: 500 <= weight <= 4000)
  • horsePower (int - admissible values: 30 <= horsePower <= 400)

Provide

  • a default constructor that sets String values to null and int values to 0
  • a parameterized constructor that sets all four instance fields to the parameter values
  • setters and getters for all instance fields
  • a decent toString method

2. Create a class CarFactory

It provides just one method public static Car createRandomCar() which creates a random car instance with value chosen from the admissible set/range.

In: Computer Science

INFIX2POSTFIX.CPP #include "stack.hpp" using namespace std; // Auxiliary method, you probably find it useful // Operands...

INFIX2POSTFIX.CPP

#include "stack.hpp"

using namespace std;

// Auxiliary method, you probably find it useful

// Operands are all lower case and upper case characters

bool isOperand(char c){

  return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');

}

// Auxiliary method, you probably find it useful

int precedence(char c)

{

  if(c == '+' || c == '-'){

    return 0;

  }

  if(c == '*' || c == '/'){

    return 1;

  }

  if(c == '^'){

    return 2;

  }

  return -1;

}

int main(){

  freopen("input_infix2postfix.txt", "r", stdin);

  string input;

  string solution;

  int line_counter = 0;

  while(cin >> solution){

    cin >> input;

    Stack<char> stack;

    string result;

     //The input file is in the format "expected_solution infix_expression",

     //where expected_solution is the infix_expression in postfix format

    for(int i=0; i<input.length(); ++i){

      // WRITE CODE HERE to store in 'result' the postfix transformation of 'input'

    }

    

    // You need to do some extra stuff here to store in 'result' the postfix transformation of 'input'

    

    // Checking whether the result you got is correct

    if(solution == result){

      cout << "line " << line_counter << ": OK [" << solution << " " << result << "]" << endl;

    }else{

      cout << "line " << line_counter << ": ERROR [" << solution << " " << result << "]" << endl;

    }

    line_counter++;

  }

}

Implement a stack and solutions to the following problems: balancing parenthesis, evaluating postfix expressions and transforming infix expressions into postfix expressions.

infix2postfix.cpp

- create main method to transform an infix expression into postfix

In: Computer Science

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