C++
#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
Node(){
data = 0;
next = NULL;
}
Node(int x){
data = x;
next = NULL;
}
};
struct LinkedList {
Node* head;
LinkedList(){
head = NULL;
}
void append(int value){
if (head == NULL){
head = new Node(value);
}
else{
Node* newNode = new Node(value);
Node* temp = head;
while(temp->next != NULL){
temp = temp->next;
}
temp->next = newNode;
}
}
void insertAt(int index, int value) {
// Provide your code
here
}
int getValue(int index){
// Provide your code
here
}
void setValue(int index, int value){
// Provide your code
here
}
void print (){
Node* temp = head;
while (temp != NULL)
{
cout << temp->data << endl;
temp = temp->next;
}
}
~LinkedList(){
Node* temp = head;
while(temp !=
NULL){
temp = temp->next;
delete head;
head = temp;
}
}
};
int main(int argc, const char * argv[]) {
LinkedList myList;
for (int i = 0; i < 6; i++) {
myList.append(i);
}
myList.insertAt(2, 77);
myList.insertAt(10, 89);
myList.append(101);
myList.setValue(0, 11);
cout << myList.getValue(2) << endl
<< endl;
myList.print();
// Expected output:
// 77
//
// 11
// 1
// 77
// 2
// 3
// 4
// 5
// 0
// 0
// 0
// 89
// 101
return 0;
}
The first function you are being asked to implement is int getValueAt(int index) . This function simply returns the value that appears in the array position specified by index .
The second function is void setValueAt(int index, int value) . Its job is to store value in the array position corresponding to index .
The last function to implement is void insertAt(int index, int value) . As the name suggests, it needs to insert the value at the index. It should not overwrite anything. If there is already a something stored at index , it should be shifted to the right. If index is larger than the current size of the list, then it needs to be resized in order to accomodate. If there is a gap between the old size of the list, and the newly inserted value, that gap should be filled with 0s
In: Computer Science
C Programming Assignment 4
Cache Simulation
Objective:
To write a C program that simulates reading and writing to a custom-sized direct-mapped cache, involving a custom-sized main memory.
The program will read all values from the ZyLab as Test Bench inputs.
Main Menu Options:
The program simulates reading from and writing to a cache based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are:
Note that when you read from ZyLab, the input values are not displayed on the screen as they are in the sample run at the end of this document.
Inputs:
Input Value Checks:
Output Messages:
All messages should be display EXACTLY as shown in the sample run; that is, prefixed by three asterisks, a space and hyphen and one more space. The message should be followed by a blank line.
*** All Input Parameters Accepted.
Starting to Process Write/Read Requests
Note that one message has been deleted from previous versions of this Specification and three new ones have been added.
*** Error - Main Memory Size is not a Power of 2
*** Error - Block Size is not a Power of 2
*** Error - Cache Size is not a Power of 2
*** Error – Block size is larger than cache size
*** Error – Cache Size is not a multiple of Block Size
*** Error – Read Address Exceeds Memory Address Space
*** Error – Write Address Exceeds Memory Address Space (The write value following the invalid address value should be read and then discarded)
*** Error – Invalid Menu Option Selected (Until configuration data has been accepted, the only valid menu options that can be entered are “1” or “4.”)
Whenever any one of these errors occurs, the program should loop back to the Main Menu.
*** Word WW of Cache Line LL with Tag TT contains Value VV
This message should appear after all successful reads or writes
WW is the word number in the cache line, LL is the line number in the cache, TT is the line’s tag value and VV is the content value in the cache.
All values are in decimal.
*** Read Miss - First Load Block from Memory (followed on the next line by the Content Message above)
*** Cache Hit (followed on the next line by the Content Message above)
*** Write Miss - First Load Block from Memory (followed on the next line by the Content Message above)
*** Cache Hit (followed on the next line by the Content Message above)
*** Memory Freed Up – Program Terminated Normally
When option 4 is entered, the memory should be freed up and the message “Memory Freed Up – Program Terminated Normally”, followed by a blank line, should be displayed before exiting the program.
Program Requirements:
Each word i of main memory is initialized with the value M–i, where M is the size of main memory in words. So, memory location 0 will contain the address of the last memory location and the last memory location will contain the address of the first memory location (i.e. 0).
Prologue & Comments:
At the very beginning of your source code (the very first lines), please include a prologue which looks like the following:
/*
Dr. George Lazik (use your full name not mine)
Programming Assignment 4: Cache Simulation
Comp 222 – Fall 2019
Meeting Time: 0800-0915 (your meeting time)
*/
// Reading input values from ZyLab
// Determining the contents of memory
ZyLab Test Benches:
Make sure your full name appears on each page of the listing and that all pages are stapled together in their correct order BEFORE you come to class.
Failure to provide this listing will result in no grade for the assignment.
Sample Test Run
The following is a sample run of one of the tests in Assignment 4’s Test Bench on ZyBooks. Note: Some recently added error conditions are not included in this run.
1
65536
512
1024
1
65536
1027
16
1
65536
1024
15
1
65537
1026
4096
1
65536
1024
18
1
65536
1024
16
3
65535
14
2
65535
3
65534
512
2
1023
4
Your output
Programming Assignment 4: Cache Simulation
Comp 222 - Fall 2019
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Block Size is Larger than Cache Size
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Cache Size is not a Power of 2
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Block Size is not a Power of 2
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Main Memory Size is not a Power of 2
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Cache size is not a multiple of block size
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** All Input Parameters Accepted. Starting to Process Write/Read Requests
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter Main Memory Address to Write:
Enter Value to Write:
*** Write Miss - First load block from memory
*** Word 15 of Cache Line 63 with Tag 63 contains the Value 14
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter Main Memory Address to Read:
*** Cache Hit
*** Word 15 of Cache Line 63 with Tag 63 contains the Value 14
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter Main Memory Address to Write:
Enter Value to Write:
*** Cache Hit
*** Word 14 of Cache Line 63 with Tag 63 contains the Value 512
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter Main Memory Address to Read:
Read Miss - First Load Block from Memory
*** Word 15 of Cache Line 63 with Tag 0 contains the Value 64513
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
*** Memory Freed Up - Program Terminated Normally
In: Computer Science
Describe the differences between a legal duty and a moral duty. Define each in your own words, and describe the differences between the two across relevant aspects, including how each is established and enforced, and consequences of not honouring the duty.
b) Give a specific, detailed example of an event where there were negative consequences for a person or group who didn’t honour a moral duty (Hint - loss of reputation is one possible negative consequence). Describe the event and explain how the consequences came about.
In: Computer Science
Create a program in java eclipse named “Forecast” and a method called “String getWeather(boolean raining, int temperature)”. Depending on the parameters, return one of four outcomes:
If it’s not raining and under 30 degrees: return “The weather is chilly”
If it’s not raining and at/over 30 degrees: return “The weather is sunny”
If it’s raining and under 30 degrees: return “The weather is snowy”
If it’s raining and at/over 30 degrees: “The weather is rainy”
You must use nested if statements for this problem.
In: Computer Science
Consider a file system in which multiple users/clients can
access the data from the disks
over storage network. Assume each user/client has its file system
and considers its storage
disks (shared with other clients) as local.
(a) Explain how this file system is different as compared to NFS
(Network File
Servers).
(b) What are the major advantages and disadvantages of this type of
file systems (do
not repeat the points mentioned in answering the part-a)?
In: Computer Science
In: Computer Science
Write a program that uses a structure to store the following inventory information in a Binary file and access it using Random Access Method: Item description Quantity on hand Wholesale cost Retail cost Date added to inventory The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file Change any record in the file For exact menu option text please see the test cases below
In: Computer Science
Given a program as shown below:
#include <stdio.h>
void function1(void);
void function2 (int, double x);
void main (void)
{
int m;
double y;
m=15;
y=308.24;
printf ("The value of m in main is m=%d\n\n",m);
function1();
function2(m,y);
printf ("The value of m is main still m = %d\n",m);
}
void function1(void)
{
printf("function1 is a void function that does not receive\n\\r values from main.\n\n");
}
void function2(int n, double x)
{
int k,m;
double z;
k=2*n+2;
m=5*n+37;
z=4.0*x-58.4;
printf ("function2 is a void function that does receive\n\\r values from main.The values received from main are:\n\\r\t n=%d \n\r\t x=%lf\n\n", n,x);
printf ("function2 creates three new variable, k, m and z\n\\rThese variable have the values:\n\\r\t 1=%d \n\r\t m=%d \n\r\t z=%lf \n\n",k,m,z);
}
In: Computer Science
Please type out, not handwrite. THANKS!!
Compare and contrast Wireless networks and Home networks impact on the future of computing in a few paragraphs.
In: Computer Science
Prepare A Demo
Objective: What are the commands you would need to use to
backup your media files like music / pictures / movie folders and
backup media files, like .mp3 / .jpg / .mp4 or .mov files, into
their respective folders from a common media folder?
Process:
A) List, line by line, the sequence of commands needed to backup your media files.
B) Provide a brief description of what each section is doing between each section.
C) Example: Copying media files, with a blank line in between, what command is being used.
Use blank lines to between sections for readability in your
documentation. It is OK to list groups of commands or comments
without extra blank lines.
(No Screenshots please)
In: Computer Science
Example code of inserting nodes, deleting nodes, and deleting specific nodes in a Linked List in C++?
How do I create nodes? explain each line of code pleasee
In: Computer Science
this is java code
package calculator;
import java.util.Scanner;
import java.lang.Math;
public class Calculator {
public static void main(String[] args) {
double numx, numy;
Scanner scanner = new Scanner(System.in);
System.out.println(" Enter an operation :");
System.out.println("1: Addition");
System.out.println("2: Subtraction");
System.out.println("3: Multiplication");
System.out.println("4: Division");
System.out.println("5: Modulus");
System.out.println("6: Power");
System.out.println("7: Square");
System.out.println("8: Factorial");
System.out.println("9: Log");
System.out.println("10: Sin");
System.out.println("11: Absolute value");
System.out.println("12: Average Of Array Elements");
String operator = scanner.next();
System.out.println();
double output;
switch(operator)
{
case "1":
System.out.print("Enter first number:");
/* We are using data type double so that user
* can enter integer as well as floating point
* value
*/
numx = scanner.nextDouble();
System.out.print("Enter second number:");
numy = scanner.nextDouble();
output = sum( numx, numy);
break;
case "2":
System.out.print("Enter first number:");
/* We are using data type double so that user
* can enter integer as well as floating point
* value
*/
numx = scanner.nextDouble();
System.out.print("Enter second number:");
numy = scanner.nextDouble();
output = Subtraction( numx, numy);
break;
case "3":
System.out.print("Enter first number:");
/* We are using data type double so that user
* can enter integer as well as floating point
* value
*/
numx = scanner.nextDouble();
System.out.print("Enter second number:");
numy = scanner.nextDouble();
output = Multiplication( numx,numy);
break;
case "4":
System.out.print("Enter first number:");
/* We are using data type double so that user
* can enter integer as well as floating point
* value
*/
numx = scanner.nextDouble();
System.out.print("Enter second number:");
numy = scanner.nextDouble();
output = Division( numx, numy );
break;
case "5":
System.out.print("Enter first number:");
/* We are using data type double so that user
* can enter integer as well as floating point
* value
*/
numx = scanner.nextDouble();
System.out.print("Enter second number:");
numy = scanner.nextDouble();
output =Modulus( numx,numy);
break;
case "6":
System.out.print("Enter first number:");
numx = scanner.nextDouble();
System.out.print("Enter second number:");
numy = scanner.nextDouble();
output = power( numx, numy);
break;
case "7":
System.out.print("Enter first number:");
numx = scanner.nextDouble();
output= Square_root( numx);
break;
case "8":
System.out.print("Enter first number:");
numx = scanner.nextDouble();
output=factorial( numx);
break;
case "9":
System.out.print("Enter first number:");
numx = scanner.nextDouble();
output=log1( numx); // log function
break;
case "10":
System.out.print("Enter first number:");
numx = scanner.nextDouble();
output=sin1( numx); //sin finction
break;
case "11":
System.out.print("Enter first number:");
numx = scanner.nextDouble();
output=absolute( numx); //absolute function
break;
case "12":
output= average( );
break;
/* If user enters any other operator apart from
* then display an error message to user
*
*/
default:
System.out.printf("You have entered wrong operator");
return;
}
System.out.println(output);
}
public static double sum(double numx, double numy)
{
double sum=0;
return sum=numx+numy;
}
public static double Subtraction(double numx, double numy)
{
double sub=0;
return sub=numx-numy;
}
public static double Multiplication(double numx, double numy)
{
double Mul=0;
return Mul=numx*numy;
}
public static double Division(double numx, double numy)
{
double Division=0;
return Division=numx/numy;
}
public static double Modulus(double numx, double numy)
{
double Mod=0;
return Mod=numx%numy;
}
public static double power(double numx, double numy)
{
double output = Math.pow(numx, numy);
return output;
}
public static double Square_root(double numx)
{
double output = Math.sqrt(numx);
return output;
}
public static double factorial(double numx)
{
double factorial=1;
for(int i = 1; i <= numx; ++i) //loop for calculation of factorial
{
// factorial = factorial * i;
factorial *= i;
}
return factorial;
}
public static double log1(double numx)
{
double output=1;
return output=Math.log(numx);
}
public static double absolute(double numx)
{
double output=1;
return output=Math.abs(numx);
}
public static double sin1(double numx)
{
double output=1;
return output=Math.sin(numx);
}
public static double average( )
{
int n =1;
Scanner scanner = new Scanner(System.in);
double total = 0;
System.out.println("Enter size of array");
n=scanner.nextInt();
int i=0;
double[] arr = new double[n];
while(i<arr.length) // while loop for getting elements in array
{
System.out.print("Enter Element No."+(i+1)+": ");
arr[i] = scanner.nextDouble();
i++;
}
for(int j=0; j<arr.length; j++){ // loop to calculate sum of array
total = total + arr[j];
}
double average = total / arr.length;
return average;
}
}
for this code draw High level flowchart.
In: Computer Science
How do I stop the comma from printing at the end of Neptune?
#include <iostream>
using namespace std;
int main() {
string planets[] = {"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"};
cout << "Contents in the array: ";
for(int i = 0; i < 8 ; i++) {
cout << *(planets + i) << ", ";
}
cout << endl;
return 0;
}
In: Computer Science
a) The ASCII code for the letter A is 1000001, and the ASCII code for the letter a is 1100001. Given that the ASCII code for the letter G is 1000111, without looking at Table 2.7, what is the ASCII code for the letter g?
b) The EBCDIC code for the letter A is 1100 0001, and the EBCDIC code for the letter a is 1000 0001. Given that the EBCDIC code for the letter G is 1100 0111, without looking at Table 2.7, what is the ASCII code for the letter g?
c) The ASCII code for the letter A is 1000001, and the ASCII code for the letter a is 1100001. Given that the ASCII code for the letter Q is 1010001, without looking at Table 2.7, what is the ASCII code for the letter q?
In: Computer Science
What is a NOSQL database? For what types of applications would be a NOSQL database preferred over a relational database. Provide the name of a NOSQL database used in the real world.
In: Computer Science