Questions
assume the following instruction frequencies/composition in the program: load (lw) 22% sub / compare 21% conditional...

assume the following instruction frequencies/composition in the

program:

load (lw) 22%

sub / compare 21%

conditional branch 20%

store (sw) 12%

add / move 12%

and 6%

4.

How long would it take to run a 100 instruction program on a single cycle datapath architecture, assuming a cycle time of 50ns?

(14)

5.

How long would it take to run the same 100 instruction program on a multi-cycle datapath architecture, assuming a cycle time of 8ns. Further assume that “lw” takes 6 cycles, “sw” takes 4 cycles, and all other instructions take 3 cycles to execute.
(14)

In: Computer Science

Code in C++, create the erase function shown in int main() /* Use of dynamic memory...

Code in C++, create the erase function shown in int main()

/* Use of dynamic memory to implement dynamic array (like vector) */

#include <iostream>
using namespace std;

class MyVector {
private:
    int* arr; //only stores ints
    int size;
    int cap;
public:
    MyVector() : arr{nullptr} {}; // Default constructor;
    ~MyVector(); // Destructor: Cleans up stuff. Here deletes arr
    void push(int ele); // inserts element into vector
    friend ostream& operator <<(ostream& os, MyVector& v);
    
    
};


int main()
{
    MyVector vec;
    vec.push(1); //should store 1 in the vec
    vec.push(2); // should store 2 into the vec
    vec.push(10); // should print all elements
    vec.erase(0) // Erase element at position 0
    cout << vec << endl; // should print remaining elements
    
}

MyVector::~MyVector() // Destructor
{
    delete[] arr;
    cout << "Destroyed vector" << endl;
    
}

ostream& operator <<(ostream& os, MyVector& v)
{
    for(int i = 0; i < v.size; i++)
        os << v.arr[i] << " ";
    return os;
}

void MyVector::push(int ele)
{
    // Check if arr == nullptr. If yes, dynamically create an array of elements. Insert ele into array
    if (arr == nullptr) {
        cap = 2;
        arr = new int[cap];
        arr[0] = ele;
        size = 1;
    }
    else {
        // Check if there is space
        if (size < cap) {
            arr[size] = ele;
            size++;
        }
        else {
            int* temp = arr;
            arr = new int[2*cap];
            for (int i = 0; i < cap; i++)
                arr[i] = temp[i];
            delete[] temp;
            cap = 2*cap;
            arr[size] = ele;
            size++;
        }

    }
    
}

In: Computer Science

in java A NavigableSet is a set that stores it’s element in order. Say we have...

in java

A NavigableSet is a set that stores it’s element in order. Say we have a bunch of items
and we want to store them in order but we don’t want any duplicates. Write a generic
class that implements a structure that does that.

In: Computer Science

C data structure Initially, we do not need to do any error checking - we can...

C data structure

Initially, we do not need to do any error checking - we can assume that the input postfix expression is syntactically correct.

Input

The input is a string that represents a postfix expression. To simplify the problem, your calculator will be restricted to operating on single-digit non-negative integers. Only the following characters are allowed in the string:

  • the operators '+', '-'. '*', and '/'

  • the digits '0' through '9'

  • the space (blank) character ' '

Example input:

  7 8 5 * +

Processing

To handle spaces in the input, need to make one minor addition to the algorithm

  if (ch is a blank)

      ignore it

   end if

Program should ask the user to enter a text file with postfix expression on a single line. we can either read the line one character at a time, or can read the line into a string and then process the string one character at a time. Your program should then print the value of the expression. program should include a loop so that the user can evaluate multiple postfix expressions. Your output might look like:

  Enter postfix expression:

   5 8 9 + *

   The value of the expression is result of postfix

   More expressions (Y or N)? Y

   Enter postfix expression:

   9 5 /

   The value of the expression is 1

   More expressions (Y or N)? N

program should perform integer calculations only(single digit only). Do not use floating-point (float or double) variables for your calculations.

--------------------------------------------------------------------------------------------------------------------

Second part would be interesting in this part we have to do error checking after calculator thoroughly tested.

Error checking

1). Invalid character in the input expression- if the error occurs, print an error message stating that an invalid character was encountered.

2) Stack is empty when the algorithm needs to remove an operand- this happens when the expression has too many operators or when the operators and operands are not ordered correctly. We call this a malformed expression, if this occurs, print an error message indicating that the expression is malformed.

3). When the loop in the algorithm ends, there should be exactly one value left on the stack and it is the value of input expression. If the input contained too many operands, there will be more than one value left on the stack. If you remove what should be the result of the expression and the stack is not empty, then the expression was malformed and should print error message indicating.

In all cases, if an error occurs do not try to continue processing the input string and do not try to print the value of the expression. Just print the error message. Do not end application- just ask user if he wants to try another expression.

In: Computer Science

In C++ Language: Program a multiple(4) choice quiz with 10 question that allows the user to...

In C++ Language: Program a multiple(4) choice quiz with 10 question that allows the user to input their choice. Validate their choice, if choice is valid continue. If choice is not valid have the user input a different answer. If the user gets 3 of the 10 choices incorrect, then the quiz is over.

In: Computer Science

Discuss the three types of communication in IPv4 network

Discuss the three types of communication in IPv4 network

In: Computer Science

Consider this class with a const variable and function: class Student { private: const int IDNum;...

Consider this class with a const variable and function:
class Student {
private:
const int IDNum;
public:
Student();
int getIDNum() const:
};
a. How do you initialize the const variable IDNum to 100? Write the code:
b. Are getters normally declared const?
c. Are setters normally declared const?
d. Can a const function call a non-const function?
e. Can a non-const function call a const function?
f. Can a const function use a non-const variable?
g. Can a non-const function use a const variable?

In: Computer Science

using matlab: 1- Using ‘input’ command, ‘prompt’ your name and ask for a grade (A, B,...

using matlab:

1- Using ‘input’ command, ‘prompt’ your name and ask for a grade (A, B, C, D, F should be accepted only, otherwise it should ask again)

2- Use ‘display’ command for the previous problem and display your name and your grade

In: Computer Science

What are the 3 goals of computer security, define them Design a Authentication mutual protocol not...

What are the 3 goals of computer security, define them

Design a Authentication mutual protocol not subject to reflection attack

What are 3 types of hashing. Draw a diagram of hash function

What is a memory layout. Draw an example

Describe Buffer Flow attack

In: Computer Science

1. Insight into RF systems a. Would a high-gain dish antenna be suitable for use as...

1. Insight into RF systems

a. Would a high-gain dish antenna be suitable for use as the antenna at the base station in a PtMP (Point to Multi-Point) setup, yes or no? Explain your answer.

2. Radio frequency terminology:

Research and concisely describe the following RF terms:

  1. Isotropic antenna
  2. Antenna gain
  3. Beam width

In: Computer Science

In JAVA • Write a program that calculates the average of a group of test scores,...

In JAVA

• Write a program that calculates the average of a group of test scores, where the
lowest score in the group is dropped. It should use the following methods:
• int getScore() should ask the user for a test score, store it in a reference
parameter variable, and validate it. This method should be called by main once
for each of the five scores to be entered.
• void calcAverage() should calculate and display the average of the four highest scores.

This method should be called just once by main, and should be passed
the five scores.
• int findLowest() should find and return the lowest of the five scores passed to it.
It should be called by calcAverage, which uses the method to determine one of
the five scores to drop.
The program should display a letter grade for each score and the average test
score.
Input Validation: Do not accept test scores lower than 0 or higher than 100.

*******(use random numbers 50-100. Don't ask the user to enter data)
********Show all test scores, the one that got dropped and the average.

*******For random numbers, use the Random class not Math.random()

In: Computer Science

Data Models 1. What is a business rule, and what is its purpose in data modeling?...

Data Models

1. What is a business rule, and what is its purpose in data modeling?

2. What is a relationship, and what three types of relationships exist?

3. What is a table, and what role does it play in the relational model?

In: Computer Science

create code for an address book console program in C++ that: Uses a basic array in...

create code for an address book console program in C++ that:

  1. Uses a basic array in the main program to hold multiple Record class objects.
  2. A Record class is to be constructed with the following member variables:
    1. Record number,
    2. first name,
    3. last name,
    4. age, and
    5. telephone number.
  3. The Record class must have a custom constructor that initializes the member variables.
  4. The Record class declaration is to be separated from the Record class implementation and these are to be placed in .h and .cpp files respectively.
  5. The program should have a perpetual menu that allows a choice of:
    1. Input information into an record,
    2. Display all information in all records, and
    3. Exit the program.
  6. The program should hold 10 records at the minimum.

In: Computer Science

Another Type of Employee The files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java, Executive.java, and Hourly.java are from...

  1. Another Type of Employee

The files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java, Executive.java, and

Hourly.java are from Listings 10.1 - 10.7 in the text. The program illustrates inheritance and polymorphism.

In this exercise you will add one more employee type to the class hierarchy (see Figure 9.1 in the text).

The employee will be one that is an hourly employee but also earns a commission on sales. Hence the class, which we’ll name Commission, will be derived from the Hourly class.

Write a class named Commission with the following features:

  • It extends the Hourly class.
  • It has two instance variables (in addition to those inherited): one is the total sales the employee has made (type double) and the second is the commission rate for the employee (the commission rate will be type double and will represent the percent (in decimal form) commission the employee earns on sales (so .2 would mean the employee earns 20% commission on sales)).
  • The constructor takes 6 parameters: the first 5 are the same as for Hourly (name, address, phone number, social security number, hourly pay rate) and the 6th is the commission rate for the employee. The constructor should call the constructor of the parent class with the first 5 parameters then use the 6th to set the commission rate.
  • One additional method is needed: public void addSales (double totalSales) that adds the parameter to the instance variable representing total sales.
  • The pay method must call the pay method of the parent class to compute the pay for hours worked then add to that the pay from commission on sales. (See the pay method in the Executive class.) The total sales should be set back to 0 (note: you don’t need to set the hours Worked back to 0—why not?).
  • The toString method needs to call the toString method of the parent class then add the total sales to that.

To test your class, update Staff.java as follows:

  • Increase the size of the array to 8.
  • Add two commissioned employees to the staffList—make up your own names, addresses, phone numbers and social security numbers. Have one of the employees earn $12.00 per hour and 20% commission and the other one earn $14.75 per hour and 15% commission.
  • For the first additional employee you added, put the hours worked at 35 and the total sales $400; for the second, put the hours at 40 and the sales at $950.

Compile and run the program. Make sure it is working properly.

//*****************************************************************

// Firm.java Author: Lewis/Loftus

//

// Demonstrates polymorphism via inheritance.

// ****************************************************************

public class Firm

{

//--------------------------------------------------------------

// Creates a staff of employees for a firm and pays them.

//--------------------------------------------------------------

public static void main (String[] args)

{

Staff personnel = new Staff();

personnel.payday();

}

}

//********************************************************************

// Staff.java Author: Lewis/Loftus

//

// Represents the personnel staff of a particular business.

//********************************************************************

public class Staff

{

StaffMember[] staffList;

//-----------------------------------------------------------------

// Sets up the list of staff members.

//-----------------------------------------------------------------

public Staff ()

{

staffList = new StaffMember[6];

staffList[0] = new Executive ("Sam", "123 Main Line", "555-0469", "123-45-6789", 2423.07);

staffList[1] = new Employee ("Carla", "456 Off Line", "555-0101", "987-65-4321", 1246.15);

staffList[2] = new Employee ("Woody", "789 Off Rocker", "555-0000", "010-20-3040", 1169.23);

staffList[3] = new Hourly ("Diane", "678 Fifth Ave.",        "555-0690", "958-47-3625", 10.55);

staffList[4] = new Volunteer ("Norm", "987 Suds Blvd.", "555-8374");

staffList[5] = new Volunteer ("Cliff", "321 Duds Lane", "555-7282");

((Executive)staffList[0]).awardBonus (500.00);

((Hourly)staffList[3]).addHours (40);

}

//-----------------------------------------------------------------

// Pays all staff members.

//-----------------------------------------------------------------

public void payday ()

{

double amount;

for (int count=0; count < staffList.length; count++)

{

System.out.println (staffList[count]);

amount = staffList[count].pay(); // polymorphic

if (amount == 0.0)

System.out.println ("Thanks!");

else

System.out.println ("Paid: " + amount);

System.out.println ("------------------------------------");

}

}

}

//******************************************************************

// StaffMember.java Author: Lewis/Loftus

//

// Represents a generic staff member.

//******************************************************************

abstract public class StaffMember

{

protected String name;

protected String address;

protected String phone;

//---------------------------------------------------------------

// Sets up a staff member using the specified information.

//---------------------------------------------------------------

public StaffMember (String eName, String eAddress, String ePhone)

{

name = eName;

address = eAddress;

phone = ePhone;

}

//---------------------------------------------------------------

// Returns a string including the basic employee information.

//---------------------------------------------------------------

public String toString()

{

String result = "Name: " + name + "\n";

result += "Address: " + address + "\n";

result += "Phone: " + phone;

return result;

}

//---------------------------------------------------------------

// Derived classes must define the pay method for each type of

// employee.

//---------------------------------------------------------------

public abstract double pay();

}

//******************************************************************

// Volunteer.java Author: Lewis/Loftus

//

// Represents a staff member that works as a volunteer.

//******************************************************************

public class Volunteer extends StaffMember

{

//---------------------------------------------------------------

// Sets up a volunteer using the specified information.

//---------------------------------------------------------------

public Volunteer (String eName, String eAddress, String ePhone)

{

super (eName, eAddress, ePhone);

}

//---------------------------------------------------------------

// Returns a zero pay value for this volunteer.

//---------------------------------------------------------------

public double pay()

{

return 0.0;

}

}

//******************************************************************

// Employee.java Author: Lewis/Loftus

//

// Represents a general paid employee.

//******************************************************************

public class Employee extends StaffMember

{

protected String socialSecurityNumber;

protected double payRate;

//---------------------------------------------------------------

// Sets up an employee with the specified information.

//---------------------------------------------------------------

public Employee (String eName, String eAddress, String ePhone,

String socSecNumber, double rate)

{

super (eName, eAddress, ePhone);

socialSecurityNumber = socSecNumber;

payRate = rate;

}

//---------------------------------------------------------------

// Returns information about an employee as a string.

//---------------------------------------------------------------

public String toString()

{

String result = super.toString ();

result += "\nSocial Security Number: " + socialSecurityNumber;

return result;

}

//---------------------------------------------------------------

// Returns the pay rate for this employee.

//---------------------------------------------------------------

public double pay()

{

return payRate;

}

}

//******************************************************************

// Executive.java Author: Lewis/Loftus

//

// Represents an executive staff member, who can earn a bonus.

//******************************************************************

public class Executive extends Employee

{

private double bonus;

//-----------------------------------------------------------------

// Sets up an executive with the specified information.

//-----------------------------------------------------------------

public Executive (String eName, String eAddress, String ePhone,

String socSecNumber, double rate)

{

super (eName, eAddress, ePhone, socSecNumber, rate);

bonus = 0; // bonus has yet to be awarded

}

//-----------------------------------------------------------------

// Awards the specified bonus to this executive.

//-----------------------------------------------------------------

public void awardBonus (double execBonus)

{

bonus = execBonus;

}

//-----------------------------------------------------------------

// Computes and returns the pay for an executive, which is the

// regular employee payment plus a one-time bonus.

//-----------------------------------------------------------------

public double pay()

{

double payment = super.pay() + bonus;

bonus = 0;

return payment;

}

}

//******************************************************************

// Hourly.java Author: Lewis/Loftus

//

// Represents an employee that gets paid by the hour.

//*******************************************************************

public class Hourly extends Employee

{

private int hoursWorked;

//-----------------------------------------------------------------

// Sets up this hourly employee using the specified information.

//-----------------------------------------------------------------

public Hourly (String eName, String eAddress, String ePhone,

String socSecNumber, double rate)

{

super (eName, eAddress, ePhone, socSecNumber, rate);

hoursWorked = 0;

}

//-----------------------------------------------------------------

// Adds the specified number of hours to this employee's

// accumulated hours.

//-----------------------------------------------------------------

public void addHours (int moreHours)

{

hoursWorked += moreHours;

}

//-----------------------------------------------------------------

// Computes and returns the pay for this hourly employee.

//-----------------------------------------------------------------

public double pay()

{

double payment = payRate * hoursWorked;

hoursWorked = 0;

return payment;

}

//-----------------------------------------------------------------

// Returns information about this hourly employee as a string.

//-----------------------------------------------------------------

public String toString()

{

String result = super.toString();

result += "\nCurrent hours: " + hoursWorked;

return result;

}

}

In: Computer Science

Hello, I need to come up with the java code for a program that looks at...

Hello, I need to come up with the java code for a program that looks at bank Account ID's and checks if it is in the frame work of Letter followed by 4 numbers, so for example "A001". I need it to be its own method, named checkAccountID() that passes the accountID as an argument to check if it is in that framework of one letter followed by 4 numbers. Any ideas?

In: Computer Science