Two different compilers are being tested for a 4 GHz. machine with three different classes of instructions: Class A, Class B, and Class C, which require one, two, and three cycles per instruction (respectively). Both compilers are used to produce code for a large piece of software. The first compiler's code uses 5 million Class A instructions, 1 million Class B instructions, and 1 million Class C instructions. The second compiler's code uses 10 million Class A instructions, 1 million Class B instructions, and 1 million Class C instructions. Which sequence will be faster according to MIPS? Which sequence will be faster according to execution time?
In: Computer Science
CompSci 251: Intermediate Computer ProgrammingLab 4 – 2019
Introduction
For this lab we will be looking at static, or class variables. Remember, instance variables are associated with a particular instance, where static variables belong to the class. If there are n instances of a class, there are n copies of an instance variable, but exactly one copy of a static variable. Underlined items are static members of the class.
The lab also uses enums to control what is an acceptable major. Enums are a special kind of class in Java that represent constant values. Enums can also have methods, which I have overridden the toString method. You do not need to change the enum CollegeMajor class. Look at the driver for how they are accessed. Also, they can be compared against other enums as if they were primitive types.
What you need to do
Create a Student class conforming to the diagram above.
Each student has a name, GPA, and major. Assume once a name is chosen it can never be
changed. This means no setter is required for name.
The class keeps track of how many students have been created and their combined GPA. These
values are used for getStudentAvg(), which computes the average for all students.
The class also manages the total number of CompSci students and their total GPA. These values
should only be affected by CompSci majors and are used for getCompSciAvg(). Take note,
CompSci majors are still considered part of all students.
The setGPA sets the GPA to be between 0.0 and 4.0. When changing a student’s GPA, it must
accurately update the totalGPA, and possibly totalCompSciGPA, static variable. If the value is not
in range, nothing happens.
The equals method returns true if all instance variables are equal.
The toString() should return a String in the format.
o Student Name: <name>, Major: <major>, GPA:
<gpa>
A simple driver is provided. When complete your code should look
like below.
Driver Output
All students:
Student name: Eva major: Biology GPA: 3.5
Student name: Taiyu major: Computer Science GPA: 4.0 Student name:
Shaina major: Civil Engineer GPA: 3.5 Student name: Megan major:
Accounting GPA: 3.0
Student name: Antonio major: Computer Science GPA: 3.0 Student
name: Jim major: Chemistry GPA: 1.5
Student name: Morgan major: Computer Science GPA: 3.5
Testing equals methods.
Does Eva equal Taiyu? They are not the same.
Does Antonio equal Antonio? They are the same.
Testing static variables.
All Students avg = 3.14 All CompSci Students avg = 3.50
Time to set all gpa values to 3.0.
If done correctly, both averages should be 3.0.
All Students avg = 3.00 All CompSci Students avg = 3.00
Time to set all gpa values of CompSci Students to 4.0. If done correctly, both averages should be different.
All Students avg = 3.43 All CompSci Students avg = 4.00
given code
public enum CollegeMajor {
COMPSCI,BIOLOGY,NURSING,ACCOUNTING,ARCHITECTURE,FINANCE,CHEMISTRY,CIVILENGINEERING;
@Override
public String toString() {
switch(this) {
case COMPSCI:
return "Computer
Science";
case BIOLOGY:
return
"Biology";
case NURSING:
return
"Nursing";
case ACCOUNTING:
return
"Accounting";
case ARCHITECTURE:
return
"Architecture and Interior Design";
case FINANCE:
return
"Finance";
case CHEMISTRY:
return
"Chemistry";
case CIVILENGINEERING:
return "Civil
Engineer";
default:
return "";
}
}
}
ublic class Driver {
public static void main(String[] args) {
Student[] students = new Student[7];
students[0] = new Student("Eva",
3.5, CollegeMajor.BIOLOGY);
students[1] = new Student("Taiyu",
4.0, CollegeMajor.COMPSCI);
students[2] = new Student("Shaina",
3.5, CollegeMajor.CIVILENGINEERING);
students[3] = new Student("Megan",
3.0, CollegeMajor.ACCOUNTING);
students[4] = new
Student("Antonio", 3.0, CollegeMajor.COMPSCI);
students[5] = new Student("Jim",
1.5, CollegeMajor.CHEMISTRY);
students[6] = new Student("Morgan",
3.5, CollegeMajor.COMPSCI);
System.out.println("All
students:");
for(Student s: students) {
System.out.println(s);
}
System.out.println("\n\nTesting
equals methods.\n");
System.out.println("Does " +
students[0].getName() + " equal " + students[1].getName() +
"?");
if(students[0].equals(students[1]))
{
System.out.println("They are the same.");
} else {
System.out.println("They are not the same.");
}
System.out.println("\nDoes " +
students[4].getName() + " equal " + students[4].getName() +
"?");
if(students[4].equals(students[4]))
{
System.out.println("They are the same.");
} else {
System.out.println("They are not the same.");
}
System.out.println("\n\nTesting
static variables.\n");
System.out.printf("All Students avg
= %.2f\n", Student.getStudentAvg());
System.out.printf("All CompSci
Students avg = %.2f\n", Student.getCompSciAvg());
System.out.println("\nTime to
set all gpa values to 3.0.");
System.out.println("If done
correctly, both averages should be 3.0.\n");
for(Student s: students) {
s.setGPA(3.0);
}
System.out.printf("All Students
avg = %.2f\n", Student.getStudentAvg());
System.out.printf("All CompSci
Students avg = %.2f\n", Student.getCompSciAvg());
System.out.println("\nTime to
set all gpa values of CompSci Students to 4.0.");
System.out.println("If done
correctly, both averages should be different.\n");
for(Student s: students) {
if(s.getMajor()==CollegeMajor.COMPSCI)
s.setGPA(4.0);
}
System.out.printf("All Students
avg = %.2f\n", Student.getStudentAvg());
System.out.printf("All CompSci
Students avg = %.2f\n", Student.getCompSciAvg());
}
}
In: Computer Science
Using java, create a class called MyString that has one String
called word as its attribute and the following methods:
Constructor that accepts a String argument and sets the
attribute.
Method permute that returns a permuted version of word. For this method, exchange random pairs of letters in the String. To get a good permutation, if the length of the String is n, then perform 2n swaps.
Use this in an application called Jumble that prompts the user
for a word and the required number of jumbled versions and prints
the jumbled words. For example,
Enter the word: mixed
Enter the number of jumbled versions required: 10
xdmei eidmx miexd emdxi idexm demix xdemi ixdme eximd xemdi xdeim
Notes:
1. It is tricky to swap two characters in a String. One way to
accomplish this is to convert your String into an array of
characters, swapping the characters in the array, converting it
back to a String and returning it.
char[] chars = word.toCharArray(); will convert a String word to a
char array chars.
String result = new String(chars); converts a char array chars into
a String.
In: Computer Science
Part 1: Find and fix errors and add following functionalities
1. There are several syntax errors in the code that are preventing this calculator from working, find and fix those errors. When they are fixed, the number buttons will all work, as well as the + (add) and -- (decrement) buttons.
a. To find the errors, open up the Developers Tool of the browser and look at the console (F12).
Verify the add functionality works. For a binary operator, you must click on the buttons in the
following order:
Hit a number button
Hit the ‘+’ button
Hit a number button
Hit the ‘Calculate’ button
Verify the decrement operator works. For a unary operator, you must click the buttons in the following order:
Hit the number button
Hit the ‘—‘ button
Implement subtraction in a similar fashion to addition:
Create a subtract function. To subtract, the user must hit a number button, then the ‘-‘ button,another number button and then the ‘Calculate’ button. The function should store the firstnumber in a global variable, similar to the add function.
Add code in the calculate button which will perform the
subtraction when the ‘Calculate’button is clicked.
Call the subtract function from the HTML file.
5. Implement the sqrt() button. Similar to the decrement function,
the sqrt() button will take the value of
the number and display the square root. Use the Math.sqrt function to calculate the square root. 6. Validate any HTML CSS and/or JavaScript errors.
Part 2: Implement 2 or more buttons
Pick any two additional buttons and make them work. When you turn in your lab put in the‘Comments’ section of Canvas, which two buttons you implemented.
CODE:
HTML:
<!doctype html> <html lang="en"> <head> <title>Calculator</title> <!-- Meta tag for keywords --> <meta name="keywords" content="Calculator" > <!-- Meta tag for description --> <meta name="description" content="ITIS 3135 Activity 5" > <!-- Meta tag for character encoding --> <meta charset="UTF-8"> <!--External Stylesheet --> <link rel="stylesheet" type="text/css" href="Activity5.css"> <!-- JavaScript function declarations --> <script src="Activity5.js"></script> </head> <body> <header> <h1>My Calculator</h1> <!-- For people who don't have JavaScript enabled--> <noscript>This web page requires JavaScript to be enabled on your browser.</noscript> </header> <main id="calc"> <!-- form for user input that represents a calculator --> <form name="frmCalc" id="frmCalc"> <p>Please enter a numeric value or use the number buttons below.</p> <!-- Text Box to enter a numeric value --> <input type="text" name="txtNumber" value="" size="20" /><br /><br/> <!-- Number buttons --> <input type="button" value="1" name="btn1" onclick="showNum(1)" /> <input type="button" value="2" name="btn2" onclick="showNum(2)" /> <input type="button" value="3" name="btn3" onclick="showNum(3)" /> <!-- ADD: Sets up operation to add current number to next number entered --> <input type="button" value="+" name="btnPlus" onclick="add()" /><br/> <!-- Number buttons --> <input type="button" value="4" name="btn4" onclick="showNum(4)" /> <input type="button" value="5" name="btn5" onclick="showNum(5)" /> <input type="button" value="6" name="btn6" onclick="showNum(6)" /> <!-- *** Subtract (Implement Me!) *** --> <input type="button" value="-" name="btnMinus" onclick="" onclick="" /><br/> <!-- Number buttons --> <input type="button" value="7" name="btn7" onclick="showNum(7)" /> <input type="button" value="8" name="btn8" onclick="showNum(8)" /> <input type="button" value="9" name="btn9" onclick="showNum(9)" /> <!-- *** Multiply (Implement Me!) *** --> <input type="button" value="*" name="btnTimes" onclick="" /><br/> <!-- Number buttons --> <input type="button" value="0" name="btn0" onclick="showNum(0)" /> <!-- *** Power (Implement Me!) Takes two values n^y *** --> <input type="button" value="^" name="btnPow" onclick=""/> <!-- *** Power2 (Implement Me!) *** Takes one value n^2--> <input type="button" value="^2" name="btnPow2" onclick=""/> <!-- *** Divide (Implement Me!) *** --> <input type="button" value="/" name="btnDivide" onclick=""/><br/> <!-- Decrements value currently displayed --> <input type="button" value="--" name="btnDecrement" onclick="decrement()" /> <!-- *** Increment (Implement Me!) *** --> <input type="button" value="++" name="btnIncrement" onclick=""/> <!-- *** Square Root (Implement Me!) *** --> <input type="button" value="sqrt()" name="btnSqrt" onclick=""/><br /> <!-- Calculates the floor of the current number being displayed --> <input type="button" value="Floor" name="btnFloor" onclick="" /> <!-- *** Round (Implement Me!) *** --> <input type="button" value="Round" name="btnRound" onclick=""/> <!-- *** Decimal (Implement Me!) *** --> <input type="button" value="." name="btnDecimal" onclick="showNum('.')" /> <br/><br/> <input type="reset" name="btnReset" value="Clear" onclick="clear()" /> <input type="button" name="btnCalc" value="Calculate" onclick="calculate()" /> </form> </main> <footer id="Validation"> <br/> <a href="https://validator.w3.org/check?uri=referer">Validate HTML</a> <a href="https://jigsaw.w3.org/css-validator/check/referer">Validate CSS</a> </footer> </body> </html> CSS:
body { font-family:"arial"; } /*Make it look more like a calculator*/ #calc { width:250px; background-color:#cccccc; text-align:center; border:outset; padding:5px; } /*Change the style of the buttons*/ input { font-family:"Courier New"; text-align:right; } /*Make the buttons that have not been implemented red*/ input.implement { background-color:red; }
JS:
//Global variables var prevCalc = 0; var calc = ""; //The following function displays a number in the textfield when a number is clicked. //Note that it keeps concatenating numbers which are clicked. function showNum(value) { document.frmCalc.txtNumber.value += = value; } //The following function decreases the value of displayed number by 1. //isNaN method checks whether the value passed to the method is a number or not. function decrement() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { num--; document.frmCalc.txtnumber.value = num; } } //The following function is called when "Add" button is clicked. //Note that it also changes the values of the global variables. function add() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { prevCalc = num; document.frmCalc.txtNumber.value = ""; calc = "Add"; } } //The following function is called when "Calculate" button is clicked. //Note that this function is dependent on the value of global variable. function calculate() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { if (calc == "Add"){ var total = previousCalc + num; document.frmCalc.txtNumber.value = total; } } function clear() { document.frmCalc.txtNumber.value = ""; prevCalc = 0; calc = ""; }
In: Computer Science
JAVA:
Implement a Queue ADT using a circular array with 5 string elements. Create a Queue object and try various operations below.
Queue myQueue = new Queue();
myQueue.enqueue(“CPS 123”);
myQueue.enqueue(“CPS 223”);
myQueue.enqueue(“CPS 323”);
myQueue.dequeue();
myQueue.enqueue(“CPS 113”);
myQueue.enqueue(“CPS 153”);
string course = myQueue.front(); // course should be CPS 223
size = myQueue.size(); // size should be 4
// output course and size
In: Computer Science
HTML mark-up text
know the following HTML tags:
· <html>
· <body>
· <head>
· <p>
· <h1>, <h2>, <h3>, etc…
· <a>
· <img>
· <br>
· <hr>
· <pre>
· <i>
· <b>
· <em>
· <sub>
· <ins>
· <strong>
· <mark>
· <cite>
· <address>
· <abbr>
After you have reviewed these HTML tags and developed a sense of how they manipulate the presentation of the mark-up, write a sample page of HTML that briefly goes over each of these tags and demonstrates how it is used. If you can, indicate a couple of the style properties that can also be manipulated on these tags with short demonstrations.
You can just make your submission the form of an informative web-page, or you can use the elements reviewed and create a webpage with creative flair. For this assignment, select your favorite poem and write mark-up to make it appears in an aesthetically pleasing manner while taking care to demonstrate your knowledge and mastery of the listed tags.
In: Computer Science
C++
Create a program that checks whether a number is a prime number and displays its factors if it is not a prime number.
Console
Prime Number Checker
Please enter an integer between 1 and 5000: 5
5 is a prime number.
Try again? (y/n): y
Please enter an integer between 1 and 5000: 6
6 is NOT a prime number.
It has 4 factors: 1 2 3 6
Try again? (y/n): y
Please enter an integer between 1 and 5000: 200
200 is NOT a prime number.
It has 12 factors: 1 2 4 5 8 10 20 25 40 50 100 200
Try again? (y/n): n
Bye!
Specifications
In: Computer Science
Time Calculator ( PROGRAM VBA EXCEL)
Create a application that lets the user enter a number of seconds and produces output according to the following criteria:
There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds.
There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to 3,600, the program should display the number of hours in that many seconds.
There are 86,400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86,400, the program should display the number of days in that many seconds.
In: Computer Science
Computer Architecture and Organization(c++)
Write a C++ program that prompts the user to enter a hexadecimal value, multiplies it by ten, then displays the result in hexadecimal. Your main function should
a) declare a char array
b) call the readLn function to read from the keyboard,
c) call a function to convert the input text string to an int,
d) multiply the int by ten,
e) call a function to convert the int to its corresponding hexadecimal text string,
f) call writeStr to display the resulting hexadecimal text string.
the hint i was given was:
#include <iostream>
#include <cstring>
using namespace std;
char decToHex(int dec)
{
char hex;
switch (dec)
{
case 0: hex = '0';
break;
case 1: hex = '1';
break;
case 2: hex = '2';
break;
case 3: hex = '3';
break;
case 4: hex = '4';
break;
case 5: hex = '5';
break;
//
//
case 10: hex = 'A';
break;
case 11: hex = 'B';
break;
//
//
case 15: hex = 'F';
}
return hex;
}
void reverseArray(char arr[])
{
int j = strlen(arr) - 1;
int i = 0;
while ( i < j )
{
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}
void intToHex(int intVal, char hexArr[])
{
int remainder;
int i = 0;
while (intVal > 0)
{
remainder = intVal % 16;
hexArr[i] = decToHex(remainder);
intVal = intVal / 16;
i++;
}
reverseArray(hexArr);
}
int hexToDec(char hex)
{
int dec;
switch (hex)
{
case '0': dec = 0;
break;
case '1': dec = 1;
break;
case '2': dec = 2;
break;
case '3': dec = 3;
break;
case '4': dec = 4;
break;
case '5': dec = 5;
break;
//
//
case 'A':
case 'a': dec = 10;
break;
case 'B':
case 'b': dec = 11;
break;
//
//
case 'F':
case 'f': dec = 15;
}
return dec;
}
int main()
{
char hexaInput[17];
char hexaResult[17] = { '\0' };
cout << "Enter hexadecimal: ";
cin >> hexaInput;
cout << "You typed: " << hexaInput << "\n";
int count = strlen(hexaInput);
double powerVal = 0.0;
int decValue = 0;
for (int i = count - 1; i >= 0 ; i--)
{
cout << hexToDec(hexaInput[i]) << "\n";
decValue += hexToDec(hexaInput[i]) * pow(16, powerVal);
powerVal++;
}
cout << "Decimal value is " << decValue << "\n";
intToHex(decValue*10, hexaResult);
cout << "For decimal " << decValue*10 << " Hexadecimal is: " << hexaResult <<
endl;
return 0;
}
In: Computer Science
Here, we will create a structure that resembles a university’s profile. The structure must contain 5 members:
- One member for number of undergraduate students
- One member for number of graduate students
- One member for number of classrooms
- One member for the name of the university (an array)
- One member for the term (fall, summer or spring; also an array)
Once you define a structure with these members (don’t forget to give your arrays a default length), go ahead and declare one structure of this type in main. Then, also inside main, initialize the members that aren’t arrays. After this, you will ask the user for the estimated lengths of the other two members. For example, “How many letters do we expect for the name of the university? ”. When you receive these two values (one for each array), make sure to check that they do not surpass the default length you gave each array. If any of these two surpass the default length(s), print out a message and exit the program (all of this is done in main as well).
Next, if the program didn’t ended, the next step is to initialize the arrays with the help of a function. You will initialize one array at a time (keep in mind that these arrays are members of a structure, so you will have to manipulate them a little different than before). This function will not return anything and it will accept an array. Inside the function, you will scan for a set of characters given by the user. Indicate the user to end with a dot.
You will have to call this function twice, a first time for the University’s name, and a second time for the term. Once you call this function two times, your structure will be fully initialized. All is left, is to print out all the members. Go ahead and print the non-array members. Then, use a function to print out the array members (you will also have to call this function twice; once for the University’s name and once for the term). This function should not return anything and it should accept an array.
Use C code to answer this question.
In: Computer Science
1, Write an appropriate compile-time initialization for a memory location named courseNumber. Store CS 158 as the initial value in the memory location. ______________________________
2, To declare a memory location to store the town where you were born, you would write _______________________. The identifier (memory location name) you should use is homeTown. It follows the rules for naming identifiers. Be sure to end your declaration with a semicolon.
3, The default data type used for floating point values is __________. You could store the amount of money in your checking account in this memory location.
4,To create a memory location to store the count for the number of correct responses use the ____________ data type.
5,Write an appropriate compile-time initialization for a memory location named lastQuestion that could store true or false as a boolean in the memory cell. ________________________
This is from my computer science c# class
In: Computer Science
Write a Java program to randomly create an array of 50 double values. Prompt the user to enter an index and prints the corresponding array value. Include exception handling that prevents the program from terminating if an out of range index is entered by the user. (HINT: The exception thrown will be ArrayIndexOutOfBounds)
*Please do it in eclipse and this is java language*
In: Computer Science
Did you vote? | Did you vote? | |
Age Group | Yes | No |
18-24 | 18 | 62 |
25-34 | 39 | 76 |
35-44 | 64 | 76 |
45-54 | 54 | 46 |
55 and older | 82 | 43 |
A survey was conducted to determine by age group the number of registered voters who cast ballots during the recent elections. The table above was the data recorded.
a. Using α = 0.01, perform a chi-square test to determine if the proportion of voters who cast ballots during the elections differs among the five groups of voters.
b. Determine the p-value using Excel (and Table 8 of Appendix A, page 861) and interpret its meaning.
c. Confirm your results using PhStat.
d. How does age appear to relate to the likelihood that a voter will cast a ballot during the elections?
In: Computer Science
Ex: int counter = 0;
is not allowed inside a class definition.
In: Computer Science
A Library Management System is designed to carry out the management of library books in the library. In order to carry out the receipt and issuance of books, the library management information system must store, organize, share, and retrieve information.
Part 1: Describe Your Library Management Information System:
Part 2: Draw a Use Case Diagram for Your System:
*Use case descriptions are optional
Part 3: Draw a Class Diagram for Your System:
Part 4: Draw a Sequence Diagram for Your System:
In: Computer Science