I need to make an application that calculates the occupancy rate for a hotel with eight floors. The user will be asked how many rooms are occupied on each floor. The program will iterate for each floor. Users must enter numbers and the rooms occupied on each floor cannot exceed 30. The occupancy rate is the number of occupied rooms/ unnoccupied. The application also needs to display the occupancy for each individual floor aswell. Each floor has a maximum of 30 rooms. There are 240 rooms in total. The application doesn't need any fancy graphics just simple text. I'm really lost where to start. I know I need to use for loops and while but I'm not sure how to apply it. Can I get some help?
Python
The code needs to be in Python
In: Computer Science
11.2 Exercise 2:
You are required to write a program that creates a float array of size 90. Using a for loop, populate the array element whose index is the value of the loop variable with the value of the loop variable (e.g. array[0] = 0, array[1] = 1 etc.) Using a second loop display the loop index and the value in the array - each pair of numbers is to be displayed on a new line.
Hi, could you please hlp me with this simple c programming problem? I'm not sure what the part in bold is asking. Below is my code for the problem so far.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
// Declare variables
int Array[90];
int i;
// Loop from 0 to 90 inclusive
for ( i = 0 ; i < 91 ; i++ )
{
Array[i] = i;
printf ("Array number %d contains value %d\n", i, Array[i]);
}
// Exit the application
return 0;
}
In: Computer Science
1. Give a command using find to search from the root directory the file program.f and redirect any errors to the file myerrors.txt
2. Give a command for finding files having the letters index as the beginning of the file name and located in your home directory (provide the absolute path)
3. Give a command for finding within a directory called /mp3collection, only those mp3 files that have a size less than 5000 Kilobytes (< 5MB).
4. Give a commmand that searches for those files that are present in the directory /home/david and its subdirectories which end in .c and which have been accessed in the last 10 minutes.
5. Give a command that searches within the directory /mp3-collection for files that have their names beginning with ’Metallica’ and whose size is greater than 10000 kilobytes (> 10 MB).
6. Give a command that searches in the same directory as above case but only for files that are greater than 10MB, but they should not have ’Metallica’ as the starting of their filenames.
7. Explain what the following commands do. What is the major difference between their outputs? a) chmod -R 755 . b) chmod -R 755 *
8. Explain the output of the following command:
pr -t -n -d -o 10 group12
9. Study the cut command and describe what is its function, provide some examples including options like -c, and -f.
10. What is the output of the following command?
sort -t: -k3,3 -n /etc/group
In: Computer Science
Ex: Write a program to randomly generate 31 positive integers
below 100 to find the median and display it on the root, and
display the remaining integers as BST (Binary Search Tree).
(Generate JTextArea panels at the bottom to display the results of
the potential, intermediate, and rearward tours.)
Write java code (Using GUI,no javafx)and show me the output.
If you can't understand the question, let me know. :)
Thank you :)
In: Computer Science
** in C language please
Write a function that remove a substring of str beginning at
index idx and length len.
// param str: the string being altered
// param idx: the starting index of the removed chunk
// param len: the number of characters to remove (length of
sub>
// removed) assumptions:
// 0 <= idx
// str is a valid string that terminates properly
//
// TODO: complete the function
void remove_substr(char str[], int idx, int len) {
In: Computer Science
(C++)
Behavior: Returns true is there exists a sequence of 3 *consecutive* values in the array such that the sum of the first two elements is equal to the third element in that sequence, false otherwise. The third element has to be within a distance of dist from the second element. False otherwise.
Example: For the array {3,4,1,3,17,3,96,21,5,20}, if dist is 7 the function returns true because 4+1=5 and the element 5 is within 7 spots from element 1.
bool exists_trio_within_distance(int*, int, int);
int main()
{
const int asize=10;
int a[asize]={3,4,1,3,17,3,20,21,5,20};
const int bsize=6;
int b[bsize]={3,4,1,3,3,7};
//////////////////////////////////////////
//test exists_trio function
//should print "A trio exists."
if (exists_trio(a,asize))
cout << "A trio
exists.\n";
else
cout << "A trio does not
exist.\n";
//should print "A trio does not
exist."
if (exists_trio(b,bsize))
cout << "A trio
exists.\n";
else
cout << "A trio does not
exist.\n";
cout << "=========================\n";
//////////////////////////////////////////////
//test exists_trio_within_distance function
//if you only want to test exists_trio,
comment
//out the below code
//change the array a to help test Function
2
a[6]=209; //change a[6] from 20 to 209
int dist=7;
//should print "A trio exists within distance
7."
if (exists_trio_within_distance(a,asize,dist))
cout << "A trio exists within
distance " << dist << "." << endl;
else
cout << "A trio does not
exist within distance " << dist << "." <<
endl;
dist=2;
//should print "A trio does not exist within
distance 2."
if (exists_trio_within_distance(b,bsize,dist))
cout << "A trio exists within
distance " << dist << "." << endl;
else
cout << "A trio does not
exist within distance " << dist << "." <<
endl;
}
In: Computer Science
Java
(a) Create a class Router which stores the information of a router. It includes the brand, the model number (String) and the price (double, in dollars). Write a constructor of the class to so that the information mentioned is initialized when a Router object is created. Also write the getter methods for those variables. Finally add a method toString() to return the router information in the following string form.
"brand: Linksys, model number: RVS4000, price: 1080.0"
Copy the content of the class as the answers to this part.
(b) Create a class ComputerShop which stores the router information in a map routerMap, whose key is the concatenation of the brand and model number, separated by ": " (a colon and a space). Write a method addRouter(Router oneRouter) which adds oneRouter to routerMap. Copy the content of the class, which any include import statement(s) required, as the answers to this part.
(c) Create a class TestComputerShop with a main() method which creates a ComputerShop object aShop and add the first router with brand "Linksys", model number "RVS4000" and price 1080. Add the second router with brand "Planet", model number "VRT-311S" and price 510. Copy the content of the class as the answers to this part.
(d) Write a method showRouter() of ComputerShop which loops through the keys of routerMap using the enhanced for-loop and directly prints each router object stored using System.out.println(). (Loop through the values is simpler but using the keys is required in this part.) This should show suitable information since the method toString() has been written in (a). Add a statement in TestComputerShop to display all the router information of aShop. Copy the content of the method, line(s) added and execution output as the answers to this part.
(e) Write a method modelNumberSet() of ComputerShop which returns model numbers of the routers in a set. You should loop through the values of routerMap using the enhanced for-loop and collect the model numbers. Add a statement in TestComputerShop to display the set using System.out.println(). Copy the content of the method, line(s) added and new execution output as the answers to this part.
(f) Write a method priceList() of ComputerShop which returns the prices of the routers in a list. You should loop through the values of routerMap using the enhanced for-loop and collect the prices of the routers. Add a statement in TestComputerShop to display the list using System.out.println(). Copy the content of the method, line(s) added and new execution output as the answers to this part.
In: Computer Science
Please make a C program named:
rotate.c
This code will contain a single function (and the include directive to your header file) to perform the rotation operation using the two integer operands passed to this function. The first integer operand is the number to be rotated. The second integer operand is the number of bit positions that the first operand must be rotated by.
EXAMPLE:
Enter a 32-bit number (>= 1 and <= 4294967295, inclusively): 1
Enter the number of positions to rotate-right the input (between 0 and 31, inclusively): 1
1 rotated by 1 position gives: 2147483648
In: Computer Science
Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program.
Use TestScoresDemo.java to test your code
public class TestScoresDemo
{
public static void main(String[] args)
{
// An array with test scores.
// Notice that element 3 contains an invalid score.
double[] badScores = {97.5, 66.7, 88.0, 101.0, 99.0 };
// Another array with test scores.
// All of these scores are good.
double[] goodScores = {97.5, 66.7, 88.0, 100.0, 99.0 };
// Create a TestScores object initialized with badScores.
try
{
TestScores tBad = new TestScores(badScores);
// The following statement should not execute.
System.out.println("The average of the bad scores is " +
tBad.getAverage());
}
catch (IllegalArgumentException e)
{
System.out.println("Invalid score found.\n" + e.getMessage());
}
// Create a TestScores object initialized with goodScores.
try
{
TestScores tGood = new TestScores(goodScores);
System.out.println("The average of the good scores is " +
tGood.getAverage());
}
catch (IllegalArgumentException e)
{
System.out.println("Invalid score found.\n" + e.getMessage());
}
}
}
In: Computer Science
Using Matlab
Write a program that print the following matrix. (hint: use nested for-loop and if-statement)
mat =
[2 -1 0 0 0
-1 2 -1 0 0
0 0 -1 2 -1
0 0 0 -1 2];
In: Computer Science
Implement the following method take takes the name of an ASCII text file and displays the frequency of each character in the file. (6 pts)
public static void CountCharacters(String filename)
{
...
}
// Main provided for testing
public static void main(String args[])
{
CountCharacters("testfile.dat");
}
Output should be in the following format:
ASCII CODE - COUNTS
10 - 1
66 - 2
104 - 1
In: Computer Science
class Counter{
private int count = 0;
public void inc(){
count++;
}
public int get(){
return count;
}
}
class Worker extends Thread{
Counter count;
Worker(Counter count){
this.count = count;
}
public void run(){
for (int i = 0; i < 1000;i++){
synchronized(this){
count.inc();
}}
}
}
public class Test
{
public static void main(String args[]) throws InterruptedException
{
Counter c = new Counter();
Worker w1 = new Worker(c);
Worker w2 = new Worker(c);
w1.start();
w2.start();
w1.join();
w2.join();
System.out.println(c.get());
}
}
The above code should print 2000 because inc() method is synchronized. However, it is printing a different number ranging from 1000 to 2000 everytime it runs. Can you explain why? How would you fix it?
In: Computer Science
2. Resourcing profiling is the first step of the risk management life cycle. Describe what is involved with this step, what challenges are involved with resource profiling. Use examples from the real world for your analysis. Your answer must be two pages in length.
In: Computer Science
Q1. Formulate the logical constraints for the following statements (where A, B, C, and D are all binary variables):
a. If A happens then B or C happens.
b. If A and B happen then C and D must happen.
c. If A happens or B does not happen then C or D must happen.
d. If A happens or B happens then C and D happen.
This has previously been posted before on Chegg but there are conflicting answers and comments to the questions/responses.
In: Computer Science
PYTHON: Implement the following algorithm to construct magic n × n squares; it works only if n is odd.
row ← n - 1
column ← n/2
for k = 1 . . . n2 do
Place k at [row][column]
Increment row and column
if the row or column is n then
replace it with 0
end if
if the element at [row][column] has already been filled then
Set row and column to their previous values
Decrement row end if end for
Here is the 5 × 5 square that you get if you follow this algorithm:
11 18 25 2 9
10 12 19 21 3
4 6 13 20 22
23 5 7 14 16
17 24 1 8 15
Write a program whose input is the number n and whose output is the magic square of order n if n is odd.
Please solve in Python
In: Computer Science