Programming Assignment 1 Performance Assessment
Objective:
To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine.
The following is what the program would look like if it were run interactively. Your program will read values without using prompts.
Inputs:
• Clock rate of machine (MHz) • Number of instruction classes (types) • CPI of each type of instruction • Total instruction count for each type of instruction
Specification:
The program calculates the output based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are:
1) Enter parameters 2) Print Results 3) Quit
“Print Results” Output Format:
The Print Results option prints out the following information as shown below. Finally use upper case letters and tabs so that your inputs and outputs look just like the example.
FREQUENCY (MHz) input value
INSTRUCTION DISTRIBUTION
CLASS CPI COUNT input value input value input value input value input value input value input value input value input value
PERFORMANCE VALUES
AVERAGE CPI computed value TIME (ms) computed value MIPS computed value
Test Run:
An example of what a test run should look like when run on a terminal on Linux is shown below. All labels should be in CAPS (as shown in the example) and blank lines between input prompts and output lines should be used as in the example.
$ ./aout
(Program Execution Begin)
1) Enter Parameters 2) Print Results 3) Quit
Enter Selection: 1
Enter the frequency of the machine (MHz): 200
Enter the number of instruction classes: 3
Enter CPI of class 1: 2 Enter instruction count of class 1 (millions): 3
Enter CPI of class 2: 4 Enter instruction count of class 2 (millions): 5
Enter CPI of class 3: 6 Enter instruction count of class 3 (millions): 7
Performance assessment:
1) Enter Parameters 2) Print Results 3) Quit
Enter Selection: 2
FREQUENCY (MHz): 200
INSTRUCTION DISTRIBUTION
CLASS CPI COUNT
1 2 3
2 4 5
3 6 7
PERFORMANCE VALUES
AVERAGE CPI 4.53
TIME (ms) 340.00
MIPS 44.12
Dr. George Lazik (display your full name, not mine)
Performance assessment:
1) Enter Parameters 2) Print Results 3) Quit
Enter selection: 3
Program Terminated Normally
Notes:
Make sure all calculations are displayed truncated to 2 decimal fractional places, using the format “%.2f” in the printf statements.
Be sure that execution time is measured in milliseconds (ms).
To typecast an int x to a float y, use y = (float)x or simply y = 1.0*x
To create proper spacing, use “\t” to tab and “\n” for a new line.
Your Submission to the zyLab:
The source code as a single file named: assignment_1.c, submitted to the zyLab for Assignment 1. It will be graded when you do. You can submit your solution up to 3 times and the best score will be recorded.
You can use any editor and/or compiler you wish, but make sure your code compiles and executes under the gcc compiler on the zyLab; otherwise you will receive 0 points.
Sample Test Bench Run on a zyLab. Note that all input prompts have been eliminated from this version.
The input values:
1 200 3 2 3 4 5 6 7 2 3
The outputs:
Note that spacing is irregular due to publishing quirks here. Use TABS for spacing and you will get correct results.
FREQUENCY (MHz): 200
INSTRUCTION DISTRIBUTION
CLASS CPI COUNT
1 2 3
2 4 5
3 6 7
PERFORMANCE VALUES
AVERAGE CPI 4.53
TIME (ms) 340.00
MIPS 44.12
PROGRAM TERMINATED NORMALLY
Assignment 1 Skeleton
#include <stdio.h>
#include <stdlib.h>
//initialize values
//
int * cpi_i; //define cpi_i as a pointer to one of more
integers
//
// procedure to read all input parameters
//
void enter_params()
{
//initialize counter variables
//
int i;
cpi_sum=0;
instr_total=0;
scanf("%d", &mhz);// input frequency
scanf("%d",&classes);// input number of instruction classes
cpi_i = (int *)malloc(classes*sizeof(int)); //dynamically
allocate an array
count_i = (int *)malloc(classes*sizeof(int));//dynamically allocate
a second array
instr_total =0;
for (i=1; i <= classes; i++)
{
scanf("%d", &cpi_i[i]);// input
instruction's cpi
scanf("%d", &count_i[i]);//
input instruction's count
instr_total += count_i[i];
cpi_sum = cpi_sum + (cpi_i[i] *
count_i[i]);
}
printf("\n");
return;
}
//function computes average cpi
//
float calc_CPI()
{
}
//function computes execution time
//
float calc_CPU_time()
{
}
//function computes mips
//
float calc_MIPS()
{
}
//procedure prints input values that were read
//
void print_params()
{
}
//procedure prints calculated values
//
void print_performance()
{
}
//main program keeps reading menu selection and dispatches
accordingly
//
int main()
{
void fee(cpi_i);//free up space previously allocated above
return 0;
}
In: Computer Science
In: Computer Science
How many times will an "X" appear in the following nested
loop?
for (outer = 0; outer <=5; outer++)
{for (inner = 1; inner <=4; inner+1)
{cout<<("X");}
}
9 |
|
10 |
|
20 |
|
24 |
|
none of the above |
In: Computer Science
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class.
2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need
a) remove the capacity parameter from the constructor and create the array with 8 as the starting size
b) create a new method called resize that takes a parameter (capacity)
c) change push() to check for length of array. If it is at the limit then call resize to increase it to twice the size Use the same main program from 1 and the two input files to test out your program. RULE: You cannot use ArrayList – you must use a primitive Java arrays.
import java.util.Iterator;
import java.util.NoSuchElementException;
public class StackOfStrings implements
Iterable<String> {
private String[] a; // holds the items
private int N; // number of items in stack
// create an empty stack with given capacity
public StackOfStrings(int capacity) {
a = new String[capacity];
N = 0;
}
public boolean isEmpty() {
return N == 0;
}
public boolean isFull() {
return N == a.length;
}
public void push(String item) {
a[N++] = item;
}
public String pop() {
return a[--N];
}
public String peek() {
return a[N-1];
}
public Iterator<String> iterator() {
return new ReverseArrayIterator();
}
public class ReverseArrayIterator implements
Iterator<String> {
private int i = N-1;
public boolean hasNext() {
return i >= 0;
}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
return a[i--];
}
public void remove() {
throw new UnsupportedOperationException();
}
}
}
Numbers.txt
20
7
99
88
1
2
3
4
30
16
19
50
55
60
61
6
68
28
32
--------------------------------------------------------------
tinyTale.txt
it was the best of times it was the worst of times
it was the age of wisdom it was the age of foolishness
it was the epoch of belief it was the epoch of incredulity
it was the season of light it was the season of darkness
it was the spring of hope it was the winter of despair
In: Computer Science
Java program
Reverse polish notation: using stack - You can use the Stack included in java.util.Stack (or your own implementation) for this problem.
Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free.
Write a program which reads an expression in the Reverse Polish notation and prints the computational result.
An expression in the Reverse Polish notation is calculated using a stack. To evaluate the expression, the program should read symbols in order. If the symbol is an operand, the corresponding value should be pushed into the stack. On the other hand, if the symbols is an operator, the program should pop two elements from the stack, perform the corresponding operations, then push the result in to the stack. The program should repeat this operations.
Input: An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character.
You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
Output: Print the computational result in a line.
Constraints:
2 ≤ the number of operands in the expression ≤ 100
1 ≤ the number of operators in the expression ≤ 99
-1 × 109 ≤ values in the stack ≤ 109
Sample Input 1
1 2 +
Sample Output 1
3
Sample Input 2
1 2 + 3 4 - *
Sample Output 2
-3
In: Computer Science
what typical activities should be performed in the stage or phase of system analysis of any methods or models of SDLC
In: Computer Science
C++ Program
A company pays its salespeople on a commission basis. The salespeople each receive $250 per week plus 11 percent of their gross sales for the sales period. For example, a salesperson who grosses $5000 in sales in the period receives $250 plus 11 percent of $5000, or a total of $812.21. Write a program (using an array of counters) determines for each salesperson their total sales, their salary and additional data points. There are 12 salesmen for the company. The input data file is "SalesPerson SalesV3.txt". It contains the salesperson number (3 digit id) followed by his sales. Each salesperson has numerous sales listed for the period. You will need to keep up with the total number of sales and of course the total sales per salesman.
Output :
1.
Print out the Sales report showing the salesmen ID, his total
number of sales, his total
sales
and his average per sale. Show the report in sorted
ordered by Sales ID.
2. Print out the same report but this time print out in sorted ordered by total sales.
3. Print out the same report again sorted on average sales.
The company is looking at a reduction in sales force. So I need to know which salesman had the smallest total sales. Print out the worsted salesman, his total sales and percentage of his sales compared to the second worsted salesman. (Just to see how off his sales really are compared to one other. ie did he have a bad sales period or he is really a bad salesman.)
SalesPerson SalesV3.txt
322 10.80
848 920.00
828 1267.00
848 8320.00
229 66330.00
254 6670.00
689 520.00
691 4880.00
828 3860.00
848 2820.00
229 7848.00
828 60.00
848 820.00
229 8115.00
546 1280.00
828 660.00
848 320.00
190 325.00
828 263.00
848 9315.00
828 3860.00
848 2093.00
322 4225.00
254 960.00
689 220.00
691 436.00
322 4210.00
689 520.00
In: Computer Science
1. Please briefly describe in one short paragraph a valuable business problem that you are interested in solving and how designing a database can help in solving this problem. You should treat this database design project as something you can put on your CV and explain to potential employers (or potential investors if you are pursuing a startup).
2. Create three tables that you will use in your database. Write the SQL code (can be done in PgAdmin or in MS Word etc.). Then write a short paragraph explaining the purpose of each table.
In: Computer Science
Use the internet and research the impact that information technology and the internet has on society, the economy, and the environment. Give positive and negative examples.
In addition, discuss strategies for safeguarding computers, mobile devices, and networks against attacks while using the internet.
In: Computer Science
SQL
Consider the following business question and determine which of the following should be included in a fact/dimension table of the star schema
What was the revenue of the McDonald’s in Russia and France in 2017?
A. Russia
B. France
C. Revenue
D. Countries
Answer for both Fact and Dimension tables.
Please determine from the question which is part of the fact, and which is part of the dimension. There should be two answers.
In: Computer Science
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only)
**Please only use #include <iostream> and switch and if-else statements only. Thank you.
Ex.
Enter a number: 68954
Sixty Eight Thousand Nine Hundred Fifty Four
Enter a number: 100000
One Hundred Thousand
Enter a number: -2
Number should be from 0-1000000 only
In: Computer Science
In C programming language how do you find if all the character on a single line in a 2 dimensional array are the same?
The program should read line by line to check if all the characters on a line are the same. For this program we want to see if the * character ever shows up on a line where it is the only character on the line. as seen below.
so lets say we have a array with the following data:
Note(this is a 5x7 two dimensional array)
D C D D * D C
D C C C D * *
* * * * * * *
D C C D * D *
* * * * * * *
So i want to return the amount of lines that have the * in every position in that row. So in this array 2 lines have all the same characters which is a * so it should print "The amount of lines where the * character is the only character that appears is 2"
In: Computer Science
Write a C program
Your program will prompt the user to enter a value for the
amount of expenses on the credit card. Retrieve the user input
using fgets()/sscanf() and save the input value in a variable. The
value should be read as type double. The user may or may not enter
cents as part of the input. In other words, expect the user to
enter values such as 500, 500.00 and 500.10. The program will then
prompt the user to enter the Annual Percentage Rate (APR) for the
credit card. This value should also be read as type double and
saved in a second variable. Next, your program will prompt the user
to enter the number of days money is borrowed. This value should be
read as type int. After the values have been entered, your program
will calculate the amount of the interest and save the result in a
fourth variable. The program will then add the interest amount to
the expense amount and save this result in a fifth variable.
Finally, it will print all five variables (expense amount, APR,
number of days, amount of interest and total amount to be paid
back) to the screen in an informative format. Ensure that the
floating point output always displays exactly two decimal places.
Also, values of a magnitude less than 1 should display a leading 0
(ex. 0.75).
For interest calculation, we will use the compound interest method,
in which, we consider not only the interest on the actual borrowed
amount, but also the interest of interest that has already accrued.
We will use the following simple formula to compute compound
interest:
P' = P(1 +
r/n)^(nt)
where:
P is the original
principal sum
P' is the new
principal sum
r is the annual
interest rate
n is the
compounding frequency (we assume it to be 12, like most US
banks)
t is the overall
length of time the interest is applied (expressed in years).
The total compound interest generated is the final value minus the
initial principal:
I = P' - P
In order to compute the power function, you need to include math.h
library and call the pow() function within it. See the man page of
pow() to find more information about it. Also note that, the number
of days money is borrowed needs to be converted to number of years.
If you simply try days/365 to express it in terms of years, the
result of the division is likely going to be incorrect. The annual
interest rate, r, can be obtained from the annual percentage rate
(APR), using r = APR/100.
Your program should check to ensure that negative values are not
input. If an improper value is entered, an error message should be
printed and the program will exit (do not re-prompt the user for a
correct value).
For input, you must use the fgets()/sscanf() combination of
Standard I/O functions. Do not use the scanf() or fscanf()
functions. Although using scanf() for retrieving numerical data is
convenient, it is problematic when used in conjunction with
character string input (as you may discover if you use it in later
labs). Therefore, it is best to get into the habit of avoiding
scanf() completely, and using the fgets()/sscanf() combination
exclusively.
In: Computer Science
You have been asked to create a project plan for the new machine learning model your company has asked you to build. List the main tasks and sub-tasks you would need to complete to create the model on AWS AND How would you measure the accuracy of the model you created?
In: Computer Science
Given the following mix of job, job lengths, and arrival times, assume a time slice of 10 and compute the completion for each job and average response time for the FCFS, SJN, SRT, and Round Robin Scheduling Algorithm.
jobs arrival time CPU cycle(ms)
A 0 16
B 3 2
C 5 11
D 9 6
E 10 1
F 12 9
G 14 4
H 16 14
I 17 1
J 19 8
In: Computer Science