How would you find if numbers in an array element add up to a certain sum so for example if my array element consists of:
INPUT: 200, 10, 50, 20
and my output asks if these elements add to:
210? YES (200+10)
260? YES (200+10+50)
30? NO
What method would you suggest to look through the elements in an array (which im going to add through a text file) and determine if these sums exist in O(n^2)?
In: Computer Science
This is my last assignment in a programming class I had to take as a prerequisite for a database course (seems odd). The instructor has been awful and I haven't learned much of anything. I use VBA at work and just can't follow C++. I'm stuck on this assignment and have no idea what I'm doing. I'm a database guy at work, I'm not a programmer. Please help.
In C++, a program that performs the following tasks:
1. Design a Book class that has three data members:
string title
int pages
double price
2. Add constructors and methods (as well as method parameters when necessary):
Book() // constructor(s)
getBookInfo() // print title, pages, price
setPrice() // change price
3. In the main() function, create two Book objects:
b1("C++ Programming", 834, 93.53)
b2("Data Structures", 217, 64.42)
4. Change the price of b2 to 55.46 using the setPrice() method.
5. Using cout, Print out book information using the getBookInfo() method as shown below:
C++ Programming 834 93.53
Data Structures 217 55.46
IN C++, a program that performs the following tasks:
1. Derive a TextBook class (child) from the Book class (parent).
2. Add new data members:
string school
double discount
3. Add new constructors and methods (as well as method parameters when necessary):
TextBook() // constructor(s)
compTextBookPrice() // price = price - discount
4. Override inherited methods:
getBookInfo() // print title, pages, price, school, discount
5. In the main() function, create two Book objects and two TextBook objects:
b1("C++ Programming", 834, 93.53)
b2("Data Structures", 217, 64.42)
tb1("Database", 365, 74.41, "YSU", 20.00)
tb2("Networks", 522, 92.58, "YSU", 20.00)
6. Using cout, print out book information as shown below:
C++ Programming 834 93.53
Data Structures 217 64.42
Database 365 54.41 YSU 20.00
Networks 522 72.58 YSU 20.00
In: Computer Science
4.4-4.6 The term arithmetic overflow refers to
the condition where the result of some computation is
outside the range of expected results. When a computation produces
a result with absolute value
smaller then the computer can represent we have arithmetic
underflow.
Answer the following 4 point questions regarding the detection of
incorrect computations when processing ALU instructions.
4.4 We have explored the potential for incorrect
answers caused by overflow when the ALU operates
on integers. For completeness, we need to examine the possibility
of underflow in integer ALU
operations. Either give an example of underflow or explain why
underflow is impossible for
integer ALU computations.
4.5 Can floating point arithmetic using the
IEEE standard format result in overflow? Either explain
why overflow is impossible for floating point or explain how the
presence of overflow can be
detected. Note: an example can be used when giving your answer, but
an example without
explanation is too poor to afford full credit.
4.6 Can floating point arithmetic using the
IEEE standard format result in underflow? Either explain
why underflow is impossible for floating point computations or
explain how the presence of underflow can be detected. Give an
example with an explanation.
In: Computer Science
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 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) {
}
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
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 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) + 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 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”.
In: Computer Science
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 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 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 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