Illustrate, by example, how a C++ struct may be passed as a parameter by value or by reference. Also, show how it can be returned from a function. Be thorough in your example and explain your code.
In: Computer Science
CPP
Task: You are to write a class called Monomial, using filenames monomial.h and monomial.cpp, that will allow creation and handling of univariate monomials, as described below.
Monomial Description
Each monomial object has following properties:
Class Details
The single constructor for the Monomial class should have 2 parameters: an floating point coefficient value (optional, with a default value of 1.0); and an integer power value (optional, with a default value of 1). If the power value is less then 1, set the power to 1. The class will need to provide internal storage for any member data that must be kept track of.
There should be member functions GetCoefficient, and GetPower, which will return the monomial’s coefficient value, and monomial’s power value, respectively. The GetPower method should return integer results. The GetCoefficient function should return its result as a float.
There should be member functions SetPower, which will set the monomial’s power to the arbitrary positive value. If the parameter is not positive then set the power to the default value 1.
There should be member function Add, which adds the one monomial to the other. The parameter of this member function need to be a constant reference to the other monomial object. The monomials can only be added if they have the same power, otherwise error message must be printed. The result of the addition is saved in the caller object.
There should be two member functions Multiply (overrides), which each allow to multiply a monomial to a number and to another monomial. The first member function need to accept floating point parameter that is used to perform multiplication of the real number on the the monomial object. The second member function need to accept a constant reference to the other monomial object. Use monomials to coefficients and powers to perform their multiplication. The result of the multiplication is saved in the caller object.
There should be a member function called Exponent that perform exponentiation (raise to power) of the monomial to the specified power value. You only can raise monomial to the positive power, if the power parameter is not positive print error message. The result of the exponentiation is saved in the caller object.
A sample driver program (called monomial-driver.cpp) is provided. It uses objects of type Monomial and illustrates sample usage of the member functions.
Your class declaration and definition files must work with my main program from the test driver, as-is (do not change my program to make your code work!). You are encouraged to write your own driver routines to further test the functionality of your class, as well. Most questions about the required behavior of the class can be determined by carefully examining my driver program and the sample execution. Keep in mind, this is just a sample. Your class must meet the requirements listed above in the specification - not just satisfy this driver program. (For instance, I haven’t tested every illegal fill character in this driver program - I’ve just shown a sample). Your class will be tested with a larger set of calls than this driver program represents.
General Requirements
Test Driver:
//
// driver.cpp -- driver program to demonstrate the behavior of
// the Monomial class
#include <iostream>
#include "monomial.h"
using namespace std;
int main()
{
// create some monomial: x, 2x, 12.5x³, -3xâ¶
Monomial m1, m2( 2.0 ), m3( 12.5, -1 ), m4( -3.0 , 6);
// display monomial
cout << "Monomial `m1` has the coefficient " << m1.GetCoefficient()
<< " and power " << m1.GetPower() << ": ";
m1.Print();
cout << "Monomial `m2` has the coefficient " << m2.GetCoefficient()
<< " and power " << m2.GetPower() << ": ";
m2.Print();
cout << "Monomial `m3` has the coefficient " << m3.GetCoefficient()
<< " and power " << m3.GetPower() << ": ";
m3.Print();
cout << "Monomial `m4` has the coefficient " << m4.GetCoefficient()
<< " and power " << m4.GetPower() << ": ";
m4.Print();
// Change monomial power
cout << "Monomial `m3` power wasn't changed: ";
m3.SetPower(-1);
m3.Print();
cout << "Monomial `m3` power was changed: ";
m3.SetPower(3);
m3.Print();
// can add monomials with the same powers
cout << "Monomial addition" << endl;
m1.Add(m2);
cout << "x + 2x = ";
m1.Print();
// cannot add monomials with different powers
cout << "x³ + 12.5x³ = ";
m2.Add(m3);
// can multiply monomial to a number
cout << "Monomial multiplication by a number" << endl;
m2.Multiply(2.5);
cout << "2x * 2.5 = ";
m2.Print();
// can multiply monomials
cout << "Monomial multiplication by a monomial" << endl;
m3.Multiply(m4);
cout << "12.5x³ * -3xⶠ= ";
m3.Print();
// can raise monomial to the power
cout << "Monomial exponentiation" << endl;
m4.Exponent(3);
cout << "(-3xâ¶)³ = "; // -27x^18
m4.Print();
cout << "(3x)â° = "; // -27x^18
m1.Exponent(-10);
return 0;
}
Test Driver Output
Monomial `m1` has the coefficient 1 and power 1: 1x^1 Monomial `m2` has the coefficient 2 and power 1: 2x^1 Monomial `m3` has the coefficient 12.5 and power 1: 12.5x^1 Monomial `m4` has the coefficient -3 and power 6: -3x^6 Monomial `m3` power wasn't changed: 12.5x^1 Monomial `m3` power was changed: 12.5x^3 Monomial addition x + 2x = 3x^1 x³ + 12.5x³ = Cannot add monomials with different powers Monomial multiplication by a number 2x * 2.5 = 5x^1 Monomial multiplication by a monomial 12.5x³ * -3x⁶ = -37.5x^9 Monomial exponentiation (-3x⁶)³ = -27x^18 (3x)⁰ = Can raise only to a positive power
In: Computer Science
Consider a class ‘A’ with a method public static void show( ). A
class ‘Derived’ is the subclass of ‘A’.
Is it possible to define the same method public static void show( )
in the Derived class. Why give reasons? Is it run time
polymorphism? (0.5 Marks)
Is it possible to define the method public void show( ) (non static
method) in the Derived class. What will happen and why give
reasons?
In: Computer Science
<!DOCTYPE html>
<html>
<body>
<!-- replace the text below with your name!-->
<!-- -->
<!-- -->
<title> name </title>
<script>
//
// Write a function that calculates the amount of money a person
would earn over
// a period of years if his or her salary is one penny the first
day, two pennies
// the second day, and continues to double each day. The program
should ask the
// user for the number of years and call the function which will
return the total
// money earned in dollars and cents, not pennies. Assume there are
365 days
// in a year.
//
function totalEarned(years) {
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the next comment block. Do not
alter //
// any code in any other part of this file. //
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the previous comment block. Do
not alter //
// any code in any other part of this file. //
/////////////////////////////////////////////////////////////////////////////////
}
var yearsWorked = parseInt(prompt('How many years will you work
for pennies a day? '));
alert('Over a total of ' + yearsWorked + ', you will have earned $'
+ totalEarned(yearsWorked));
</script>
</body>
</html>
In: Computer Science
On Lab 10 you did Chapter 8’s Programming Exercise 13, using the name Lab10TestScores and assuming that the class has ten students and five tests. Now let’s rewrite it to use dynamic arrays so that it will work for any number of students and any number of tests. Call this new program Lab11TestScores. Modify the program so that it asks the user to enter the number of students and the number of tests before it reads the data from the file named Lab11ScoresData.txt. (Two data files, Lab11ScoresData_5_3.txt and Lab11ScoresData_11_6.txt, are provided so you can use to test your program.). Let me know if you have questions. #include #include using namespace std; void readFile(string names[10], int scores[][5]) { ifstream in("Lab10ScoresData.txt"); for (int i = 0; i < 10; i++) { in >> names[i] >> scores[i][0] >> scores[i][1] >> scores[i][2] >> scores[i][3] >> scores[i][4]; } } void average(int scores[][5], float avg[], char grade[]) { int total; for (int i = 0; i < 10; i++) { total = 0; for (int j = 0; j < 5; j++) total += scores[i][j]; avg[i] = (float)total / (float)5; } for (int i = 0; i < 10; i++) { if (avg[i] >= 90) grade[i] = 'A'; if (avg[i] < 90 && avg[i] >= 80) grade[i] = 'B'; if (avg[i] < 80 && avg[i] >= 70) grade[i] = 'C'; if (avg[i] < 70 && avg[i] >= 60) grade[i] = 'D'; if (avg[i] < 60 && avg[i] >= 50) grade[i] = 'E'; if (avg[i] < 50) grade[i] = 'F'; } } void sortByName(string names[], float avg[], char grade[]) { for (int i = 0; i < 9; i++) { for (int j = i + 1; j < 10; j++) { if (names[i] > names[j]) { string n = names[i]; names[i] = names[j]; names[j] = n; float a = avg[i]; avg[i] = avg[j]; avg[j] = a; char g = grade[i]; grade[i] = grade[j]; grade[j] = g; } } } } void output(string names[], float avg[], char grade[]) { cout << "Name\tAverage\tGrade\n"; for (int i = 0; i < 10; i++) { cout << names[i] << "\t" << avg[i] << "\t" << grade[i] << endl; } } void countGrade(char grade[]) { int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0; cout << "\n\nGrade\tCount\n"; for (int i = 0; i < 10; i++) { if (grade[i] == 'A') a++; if (grade[i] == 'B') b++; if (grade[i] == 'C') c++; if (grade[i] == 'D') d++; if (grade[i] == 'E') e++; if (grade[i] == 'F') f++; } cout << "A\t" << a << endl; cout << "B\t" << b << endl; cout << "C\t" << c << endl; cout << "D\t" << d << endl; cout << "E\t" << e << endl; cout << "F\t" << f << endl; } int main() { string names[10]; int scores[10][5]; float avg[10]; char grade[10]; readFile(names, scores); average(scores, avg, grade); sortByName(names, avg, grade); output(names, avg, grade); countGrade(grade); system(" pause "); return 0; }
Lab11ScoresData_11_6.txt.
Johnson 85 83 77 91 76 99 Aniston 80 90 95 93 48 100 Cooper 78 81 11 90 73 54 Gupta 92 83 30 69 87 78 Blair 23 45 96 38 59 82 Clark 60 85 45 39 67 67 Kennedy 77 31 52 74 83 77 Bronson 93 94 89 77 97 80 Sunny 79 85 28 93 82 45 Smith 85 72 49 75 63 92 Groot 90 87 94 75 100 100
Lab11ScoresData_5_3.txt
Johnson 85 83 77 Aniston 80 90 95 Cooper 78 81 11 Gupta 92 83 30 Blair 23 45 96
In: Computer Science
Linked Lists
Problem 1
Implement a program that reads the following ages (type int) from
text file ages.txt and stores
them in a linked list:
16 18 22 24 15 31 27 19 13
Implement the class LinkedList along with any applicable member
functions (e.g. void
insert(int num)).
Perform the following actions on the list (if applicable, use
recursion):
1. Display the data in the list
2. Insert 18 at the front of the list
3. Insert 23 at the end of the list
4. Insert 25 after the number 24
5. Compute the average age
6. Sort the ages in ascending order
7. Determine how many people are 18 or older
Problem 2
Implement a program that reads the following data (two strings, one
double) from text file
balances.txt and stores it in a linked list:
John Miller 2508.13
Carolyn Spacer 188.54
Mark Lee 1816.82
Sophia Brown 3200.68
Jim Gomez 12068.34
Carlos Mendoza 783.41
Erica Robertson 2000.67
Implement the class LinkedList along with any applicable member
functions (e.g. void
moveToEnd(string fullName)).
Perform the following actions on the list:
1. Display the data in the list
2. Remove the person with the lowest balance
3. Display the name and balance of the person with the most
money
4. Display the average balance of people with a balance of $2,000
or more
5. Find Sophia Brown and move her to the end of the list (use
multipurpose helper
functions to make this easier)
In: Computer Science
Objective in JAVA (Please show output and have the avergae number of checks also.):
Implement both linear search and binary search, and see which one performs better given an array 1,000 randomly generated whole numbers (between 0-999), a number picked to search that array at random, and conducting these tests 20 times. Each time the search is conducted the number of checks (IE number of times the loop is ran or the number of times the recursive method is called) needs to be counted and at the end the total number of checks should be averaged.
A few notes
Each algorithm (linear search and binary search) is ran 20 times
Each time a new sorted array of whole numbers is created and populated with random values from 0-999
A value to be searched in the said array is randomly selected from the range 0-999
Each algorithm must display if that number was successfully found
Each algorithm must display the number of checks it took to determine the above answer
It is advisable to create a method that returns the sorted array
Populate the array with random numbers
Search the array next
Return whether or not the value was found in the array
Implement both searches as a method
However instead of returning whether or not it found the number it should return the number of checks.
Whether the value is or is not found can be printed in the method
Binary search is fairly simple to create using recursion
Do not count the out of bounds or stopping index as a check
Example:
Welcome to the search tester. We are going to see which algorithm performs the best out of 20 tests
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 753
Binary Checks: 8
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 834
Binary Checks: 10
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 515
Binary Checks: 6
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 757
Binary Checks: 7
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 395
Binary Checks: 9
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 117
Binary Checks: 7
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 334
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 521
Binary Checks: 9
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Not Found
Searching using binary search
Not Found
Linear Checks: 1000
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 901
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 626
Binary Checks: 8
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 361
Binary Checks: 9
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 630
Binary Checks: 9
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 443
Binary Checks: 7
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 818
Binary Checks: 10
Searching using linear search
Found!
Searching using binary search
Found!
Linear Checks: 288
Binary Checks: 7
The average number of checks for 20 were:
Linear Search 664
Binary Search 8
In: Computer Science
In: Computer Science
Requirements Specification (this is a fictional scenario)
A large business, with several medical practices, contacted your company to create a database design. You received the task to investigate if there is a need for a hierarchy based on the specifications below, and to create the hierarchy analysis if needed. You must not create the entire analysis but only the aspects related to the hierarchy as described in the instructions, class lectures and sample examples. This is the relevant fragment from the requirements specification related to your task.
In the practice we have medical doctors, nurses, staff and other employees (e.g. cleaners for which we just keep contact information: name, SSN, phone).
For the doctors we keep the name, SSN, phone, email, main specialty, medical school. A doctor may have appointments and write prescripions. For nurses we keep the name, SSN, phone, and nurse program they completed. A nurse will prepare the patient during the visit and may collect various data. For staff we keep the name, SSN, phone and their role (e.g. receptionist, scheduler, accountant). Based on the practice policies, a nurse will not be allowed to perform staff duties.
The company wants to keep a log with who was working daily, between what hours and in which role. The company also wants to fast identify the role of a person in the organization (e.g. doctor, nurse, ...), based on the last name or id.
In: Computer Science
Generate a random list NUMBERS of size 100.
Sort NUMBERS using QUICKSORT until the sublist has size 15 or less; then use INSERTIONSORT on the sublist.
In: Computer Science
In: Computer Science
System Analysis and Design
please simple your answers as you can and don't copy.
Question One
What are the roles of a project sponsor and the approval committee during the different SDLC phases?
Question Two
As the project sponsor, you suggested that your company that runs multiple local supermarkets should provide an online shopping service to increase sales during COVID-19 pandemic. Write a system request to propose this project.
|
System request |
|
|
Project Sponsor |
|
|
Business Need |
|
|
Business Requirements |
|
|
Business Value |
|
|
Special Issues or Constraints |
|
Question Three
Assume the following scenario:
A small company needs to develop an information system for the Finance and Accounting Department. As an analyst which process model would you prefer and why?
Question Four
There are three techniques which help users discover their needs for the new system, list and compare these techniques in terms of impactful changes. Also, explain BPR.
In: Computer Science
# How do you select the the vector c(7, 8, 9) using the following four approaches
# (1) Using the [[]] operator once and only once # Your code below
(2) Using the [] operator once # Your code below
(3) Using the $ operator # Your code below
(4) Using a column vector name without using the $ operator # Your code below
In: Computer Science
Write a method that will have a C++ string passed to it. The string will be an email address and the method will return a bool to indicate that the email address is valid.
Email Validation Rules: ( These rules are not official.)
1) No whitespace allowed
2) 1 and only 1 @ symbol
3) 1 and only 1 period allowed after the @ symbol. Periods can exist before the @ sign.
4) 3 and only 3 characters after the period is required.
*****************************
Program will prompt for an email address and report if it is valid or not according to the rules posted above. The program will loop and prompt me to continue.
*****************************
In: Computer Science
QUESTION 1:
Imagine that the IRA is giving a stimulus package in the COVID-19
season. The package amount is determined by the number of adults in
the family and the total amount of salary the family gets.
Each adult will get 1200 dollars if the total salary is 100000 or less.
Each adult will get 800 dollars if the total salary is 150000 or less.
Write a python program to ask the user the number of adults in the family and the total number of family salary and determine the total amount of stimulus package the IRA will provide for that family.
QUESTION 2:
Write a program that will ask the user length and width of a right triangle and find the area of the right-angled triangle. The formula for finding the area of a right-angle triangle is
ab/2. Also, find out the result if you calculate as (ab)/2. Is it the same? If it is same, why it is the same. If it is not the same, why it is not the same.
In: Computer Science