In: Computer Science
Please use c# and write a console application
Part 1) A small airline has just purchased a computer for its
newly automated reservations system. You have been asked to develop
a new system. You are to write an application to assign seats on
each flight of the airline’s only plane. The plane has ten rows and
each row has 2 seats (total capacity: 20 seats). The first five
rows are for first class passengers, while the remaining rows are
for economy passengers. The application is used by an airline
employee who is given the task of assigning all seats to passengers
(one passenger at a time). Your application should display the
following alternatives: Please type 1 for First Class and Please
type 2 for Economy or type 3 to see the status of all seats. If the
user types 1, your application should assign a seat in the
first-class section (rows 1–5). If the user types 2, your
application should assign a seat in the economy section (rows
6–10).
If the user types 3, the application will display the status of all
seats (“A” for available and “X” for booked) as shown below. The
application will continue to ask for the user’s input until the
flight is full or the user suggests that they do not want to assign
anymore seats.
Availability Status:
X X
X X
X A
A A
A A
X X
X X
X X
X X
A A
Your application should never assign a seat that has already been assigned. When the economy section is full, your application should ask the person if it is acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message "Next flight leaves in 3 hours." You will need to use a multi-dimensional array to solve this problem.
Part 2) Use a one-dimensional array to solve the following
problem: A company pays its salespeople on a commission basis. The
salespeople receive $200 per week plus 9% of their gross sales for
that week. For example, a salesperson who grosses $5000 in sales in
a week receives $200 plus 9% of $5000, or a total of $650. Write an
application (using an array of counters) that determines how many
of the salespeople earned salaries in each of the following ranges
(assume that each salesperson’s salary is truncated to an integer
amount):
a) $200–299
b) $300–399
c) $400–499
d) $500–599
e) $600–699
f) $700–799
g) $800–899
h) $900–999
i) $1000 and over
The application will accept sales amount until the user enters -1
to end (as shown in figure 2.1 below). At this point, the
application calculates the salary and updates the appropriate
counter of the array. For instance, if the salesperson gets a total
salary of $565, you will update the counter that is counting totals
between the $500-$599 range.
Figure 2.1. Receiving input from user
Note that you do NOT need to store the individual salary of the salesperson. Summarize the results in tabular format Use only a for loop to display the output.
Final output showing all ranges and the number of agents that
received commission in that range
In: Computer Science
Python
The following dictionary contains the list of US states with their abbreviations as keys and full names as values:
states = {
'AK': 'Alaska',
'AL': 'Alabama',
'AR': 'Arkansas',
'AS': 'American Samoa',
'AZ': 'Arizona',
'CA': 'California',
'CO': 'Colorado',
'CT': 'Connecticut',
'DC': 'District of Columbia',
'DE': 'Delaware',
'FL': 'Florida',
'GA': 'Georgia',
'GU': 'Guam',
'HI': 'Hawaii',
'IA': 'Iowa',
'ID': 'Idaho',
'IL': 'Illinois',
'IN': 'Indiana',
'KS': 'Kansas',
'KY': 'Kentucky',
'LA': 'Louisiana',
'MA': 'Massachusetts',
'MD': 'Maryland',
'ME': 'Maine',
'MI': 'Michigan',
'MN': 'Minnesota',
'MO': 'Missouri',
'MP': 'Northern Mariana Islands',
'MS': 'Mississippi',
'MT': 'Montana',
'NA': 'National',
'NC': 'North Carolina',
'ND': 'North Dakota',
'NE': 'Nebraska',
'NH': 'New Hampshire',
'NJ': 'New Jersey',
'NM': 'New Mexico',
'NV': 'Nevada',
'NY': 'New York',
'OH': 'Ohio',
'OK': 'Oklahoma',
'OR': 'Oregon',
'PA': 'Pennsylvania',
'PR': 'Puerto Rico',
'RI': 'Rhode Island',
'SC': 'South Carolina',
'SD': 'South Dakota',
'TN': 'Tennessee',
'TX': 'Texas',
'UT': 'Utah',
'VA': 'Virginia',
'VI': 'Virgin Islands',
'VT': 'Vermont',
'WA': 'Washington',
'WI': 'Wisconsin',
'WV': 'West Virginia',
'WY': 'Wyoming'
}
Write a program that randomly displays an abbreviation from this list, and then asks the user to enter the full name that matches that abbreviation. Once the user guesses, let the user know whether they are correct or incorrect. If they are incorrect, display the correct answer to the user.
In: Computer Science
Write a Python program to take as input 5 birthdays from 5 users (1 each) and output them in chronological order. Dates should include the month and day (not year) in the format “June 6” as a single input per user.
In: Computer Science
In: Computer Science
Write a program in Java that asks a user for one integer between 1 and 10 (inclusively). Write a switch statement writes out the number in english (i.e. 1 is “one”, etc).
In: Computer Science
Encode Diffie Hellamn exchange in software by writing a small program that accepts the values of p and g, and randomly generates the secret numbers SA and SB, and derives the Diffie Hellman secret.
Test it on the following examples:
p = 11, g = 13
p = 7, g = 17
p = 17, g = 13
In: Computer Science
Java
3. Describe the divide-and-conquer search algorithm and explain its efficiency. Consider two different Split functions: Split = Lo, and Split = (Lo + Hi) / 2. Draw the trees of recursive calls. Assume that we are searching a large data base with 4 million items represented as an ordered array. How many probes into the list will the binary search require before finding the target or concluding that it cannot be found? Assume that it takes 1 microsecond to access an item, estimate the execution time of the binary search.
In: Computer Science
You have been approached by the Statistics Canada to create a C# program to calculate the average salary of people with university degrees, college diplomas, and high school diplomas. Using a while loop, you are to process salary data until the user indicates that you should stop (there could be 0 or more data values). For each person processed, the program must first input an education type (char edType) (‘U’ or ‘u’ for university degrees, ‘C’ or ‘c’ for college diplomas, and ‘H’ or ‘h’ for high school) and then a salary (double salaryData). The program stops accepting input when the user enters a ‘Q’ or ‘q’ for quit (use a sentinel value while loop). Your main data processing loop should be conditioned on the fact that the user has not signalled quit. It might look something like:
while(char.ToUpper(edType) != ‘Q’)
This implies that like any sentinel value loop, you must seed the loop (input a value) PRIOR to entering the loop. Inside the loop the salary data is entered and processed. Once the main loop terminates, the average salary for each of the three education types should be printed out. Be sure to print an error message if the user enters an invalid education type or a negative salary.
In: Computer Science
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