Questions
1. a) Write a C program to calculate |A-B|. You should type in A and B...

1.

a) Write a C program to calculate |A-B|. You should type in A and B when running the program.

b) Write a C program using a function to calculate (A-B)^(1/2)

-If A > B, the result will be (A-B)^(1/2)

-If A < B,the result will be (B-A)^(1/2)i

-You should type in A and B when running the program.

In: Computer Science

Peterson algorithm operating systems can someone explain to me what will be shared between the two...

Peterson algorithm operating systems can someone explain to me what will be shared between the two processes? and how is the order of execution in the two processes? if possible by drawing it will be better

i am mainly confused on how the order of execution between the two processes will be and how will the data be shared between them. i am also confused how the program counter will work between them

In: Computer Science

JAVA coding language: Consider the method getAllCharAsString: public statis String getAllCharAsString(String inputStr, char target) { }...

JAVA coding language:

Consider the method getAllCharAsString:

public statis String getAllCharAsString(String inputStr, char target) {

}

The method accepts a String parameter, inputStr, and a char parameter, target. It returns the result string consisting of all the characters in inputStr which match the target character (matching is case sensitive, for example, 'c' does not match "C"). If the characters match, the character is appended to the result String. After all the characters in inputStr have been compared, the method returns the result String. The method returns the empty String if there were no matches. Assume the inputStr is a String with length >= 0.

Example 1:

String str = "Open the pod bay doors Hal.";

String resStr = getAllCharsAsString(str, 'o');

resStr would be the String, "ooo".

Example 2:

String str = "Open the pod bay doors Hal.";

String resStr = getAllCharsAsString(str, 'z');

resStr would be the empty String, " ".

Write the getAllCharAsString method body in the box below.

In: Computer Science

c++ programing. Objectives Further practice with classes Use of inheritance Use compositions Define a class called...

c++ programing.

Objectives

  • Further practice with classes
  • Use of inheritance
  • Use compositions

Define a class called Person with private members name of type string, and money of integer type. The class has the public member functions set(), getMoney(), print(), and a parameterized constructor with default values.

Define a class called Patient with private data members name of type string, durationOfTreatment, and TreatmentCost of type integer. The class has the public member functions set(), getCost(), getDuration(), print(), and a parameterized constructor with default values.

Define a class called Doctor that publicly inherits the class Person and has the private members numberOfPatients,totalCost, list[] (an array of type Patient), and calculateTotalCost(). The class has the public member functions set(), print(), and a parameterized constructor with default values.

Implement all member functions, enforcing the principle of least privileged.

The following driver produces the given sample input / output.

int main()

{

            Doctor Hakeem;

            Hakeem.set("Ali Omar", 3000, 3);

            Hakeem.print();

            return 0;

}

Sample input / output:

Enter the name, duration, and cost of treatment number 1: Allergies 23 150

Enter the name, duration, and cost of treatment number 2: Bronchiectasis 15 280

Enter the name, duration, and cost of treatment number 3: Gallstones 10 50

Ali Omar has 3000 dirham and treated the following patients:

        Allergies was treated for 23 minutes, at a cost 150 dirham per minute

        Bronchiectasis was treated for 15 minutes, at a cost 280 dirham per minute

        Gallstones was treated for 10 minutes, at a cost 50 dirham per minute

The total cost of the 3 patients is 8150 dirham

The overall total of money is 11150 dirham

In: Computer Science

Given the relation R = {(n, m) | n, m ∈ ℤ, n ≥ m}. Which...

Given the relation R = {(n, m) | n, m ∈ ℤ, n ≥ m}. Which of the following statements about R is correct?

R is not a partial order because it is not antisymmetric

R is not a partial order because it is not reflexive

R is a partial order

R is not a partial order because it is not transitive

In: Computer Science

Complete the following recursively defined functions. Base case ?(0)=3 Recursive case ?(?) = 3?(? − 1)...

Complete the following recursively defined functions.

Base case ?(0)=3

Recursive case ?(?) = 3?(? − 1) + 7 for n ≥ 1.

?(1) = ______

f(2) = _______

f(3) = ______

f(4) = ______

Base case ?(0)=1, ?(1)=2

Recursive case ?(?) = ?(? − 1)?(? − 2) for n ≥ 2.

g(2) = ______

g(3) = ______

g(4) = ______

g(5) = ______

In: Computer Science

Using C++ If you have 2 plants (A and B) with the hight of plant A...

Using C++

If you have 2 plants (A and B) with the hight of plant A is less than the hight of plant B. However, the hight of plant A is growing faster than the hight of plant B (the hight is measured in centimetres and the hight growth rate is matured daily). Write a program that prompts the user to enter the hight and the hight growth rate of each plant. The program should check that the hight of plant A is less than the hight of plant B and that the growth rate of plant A is higher than the growth rate of plant B and it should not work otherwise. The program outputs after how many days the hight of plant A will be greater than or equal to the hight of plant B, and the hight of both plants at that time.

A sample input and output is as follows:

First Run:

Enter the hight of plan A (in centimetres): 26

Enter the hight growth rate of plant A: 0.04 Enter the hight of plant B: 25

Enter the hight growth rate of plant B: 0.02

Plant A hight should be less than plant B hight and plant A growth rate should be higher than plant B growth rate.

Second Run:

Enter the hight of plan A (in centimetres): 22

Enter the hight growth rate of plant A: 0.04

Enter the hight of plant B: 25

Enter the hight growth rate of plant B: 0.02

The hight of plant A will be greater than or equal to the hight of plant B after 7 days.

Plant A hight will become 28.9505

Plant B hight will become 28.7171

In: Computer Science

Justify the statement “Spam detection is perhaps the classic example of pattern recognition”.

Justify the statement “Spam detection is perhaps the classic example of pattern recognition”.

In: Computer Science

Question1: Define a class Human that contains: - The data fields "first name" and "last name"...

Question1: Define a class Human that contains: - The data fields "first name" and "last name" - A constructor that sets the first and last name to the instance variables. Create also a no-argument constructor - A getName() method which prints the first and last name Define the class Student which inherits Human and contains: - Private data field "mark" of type integer and a constructor which calls the superclass constructor Define the class Worker which inherits Human and contains: - Private date fields "wage" and "hours worked", and a constructor which calls the superclass constructor - A setWageInfo() method which sets the wage information to the instance variables - A calculateWage() method which calculates a worker’s salary based on wage and hours worked Write a program called HumanTest that instantiates two Human objects (one using the noargument constructor and another using the constructor with parameters). Call the method getName(). Create a Student object which calls the getName() method. Create a Worker object which calls the methods getName(), setWageInfo(), and claculateWage().

In: Computer Science

Question 2: Design a class named Square that contains data fields side and surfaceArea, and a...

Question 2: Design a class named Square that contains data fields side and surfaceArea, and a method called getSurfaceArea(). Create a child class named Cube. Cube contains a getCubeSurfaceArea() method that calculates the cube surface area. Write a program called DemoSquare that instantiates a Square object and a Cube object and displays the surface areas of the objects. Use the methods created to set the value of the side, and return the surface area. Hint: square area= side*side, Cube surface area= 6 × side2

In: Computer Science

Design an algorithm that minimises Ccmp, the number of comparisons of two books’ labels in the...

Design an algorithm that minimises Ccmp, the number of comparisons of two books’ labels in the alphabetical order, and Cmov, the number of book movements (one movement is counted whenever a book is moved from one location to another) in the worst case. Suppose there arenbooks on the main shelf, which haveal ready been sorted in an ascending alphabetical order. The m newly arrived books are carried into the library on a portable shelf.

a) Scenario 1: The newly arrived books have also been sorted in an ascending alphabetical order and you are allowed to use a temporary shelf of an infinite capacity. Design an algorithm (description + pseudo code) for the robot to arrange the new books onto themain shelf using Ccmp=Θ(n+m) label comparisons and Cmov=Θ(n+m) book movements in the worst case. Explain why your algorithm has the stated worst case complexity (ignoring the constant and choosing the dominant term in your analysis).

Algorithm ArrangingBooksScenario1(A,B,C,n,m)

//A,B, and C represent the arrays of book labels for the main, the portable, and the temporary shelves

//COMPLETE WITH YOUR PSEUDO CODE HERE

b) Scenario 2: There is no temporary shelf to use in the library and the number of newly arrived books,m, is a small constant compared ton, for instance,m=10. Design an algorithm (description + pseudo code) for the robot to arrange the new books onto the main shelf using Ccmp=Θ(log(n)) label comparisonsin the worst case. What is the number of book movements Cmov incurred in the worst-case of your algorithm and why?

Algorithm ArrangingBooksScenario2(A,B,n,m)

// A and B represent the arrays of book labels for the main and the portable shelves

//COMPLETE WITH YOUR PSEUDO CODE HERE

P/s: I have already posted this question, but haven't received a useful idea for it. So, please help me with a useful idea and more detailed pseudocode.

In: Computer Science

Discuss how you would network a university with two campuses, taking into account the various sections...

Discuss how you would network a university with two campuses, taking into account the various sections of that campus (computer labs, health clinic, offices, security post, etc), discussing the choice of technologies, devices, topology/topologies, network types, protocols and anything else you would use and justifying your choices

In: Computer Science

For the prelab assignment, you may not use the if statement nor may you use the...

For the prelab assignment, you may not use the if statement nor may you use the if/else statement. You are to write a program that calculates factorials from 1 up to and including a maximum number given by the user. Because factorials get large quickly, use long unsigned int as the type for the number entered by the user as well as the factorials you are calculating. If the user enters a 0, print an error message. Then ask if the user wishes to continue the program or quit.

In: Computer Science

Suggest one or more analysis pattern for the following application domains: PLEASE DO NOT HAND WRITE...

Suggest one or more analysis pattern for the following application domains: PLEASE DO NOT HAND WRITE THE ANSWER!! PLEASE ANSWER ALL PARTS OF THE QUESTION!!

A) Accounting Software

B) Email software

C) Internet Browsers

D) Word - Processing software

E) Website creation software

In: Computer Science

Q#1: Take a real-world scenario and Implement it in C++ program. Your program should consist of...

Q#1: Take a real-world scenario and Implement it in C++ program. Your program
should consist of the following:
1. Constructors
2. Pointers
3. Private and Public keywords
4. Reference by return
5. Const keyword
6. Passing Object as argument

In: Computer Science