Questions
(C++) Write a program that can be used to calculate the federal tax. The tax is...

(C++) Write a program that can be used to calculate the federal tax. The tax is calculated as follows: For single people, the standard exemption is $4,000; for married people, the standard exemption is $7,000. A person can also put up to 6% of his or her gross income in a pension plan. The tax rates are as follows:

If the taxable income is: Between $0 and $15,000, the tax rate is 15%. Between $15,001 and $40,000, the tax is $2,250 plus 25% of the taxable income over $15,000. Over $40,000, the tax is $8,460 plus 35% of the taxable income over $40,000. Prompt the user to enter the following information: Marital status If the marital status is “married,” ask for the number of children under the age of 14 Gross salary (If the marital status is “married” and both spouses have income, enter the combined salary.) Percentage of gross income contributed to a pension fund Your program must consist of at least the following functions: Function getData: This function asks the user to enter the relevant data. Function taxAmount: This function computes and returns the tax owed.

To calculate the taxable income, subtract the sum of the standard exemption, the amount contributed to a pension plan, and the personal exemption, which is $1,500 per person. (Note that if a married couple has two children under the age of 14, then the personal exemption is $1,500 ∗ 4 = $6,000.) Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.

An input of : m, 5, 50000, 6

Should have a federal tax amount of: 5875.00

In: Computer Science

Data Structures Use good style. Make sure that you properly separate code into .h/.cpp files. Make...

Data Structures

Use good style. Make sure that you properly separate code into .h/.cpp files. Make sure that you add preprocessor guards to the .h files to allow multiple #includes.

Overview

You will be writing the classes Grade and GradeCollection. You will be writing testing code for the Grade and GradeCollection classes.

Part 1 – Create a Grade Class

Write a class named Grade to store grade information.

Grade Class Specifications

  1. Include member variables for name (string), score (double).
  2. Write a default constructor.
  3. Write a constructor that takes values for all member variables as parameters.
  4. Write a copy constructor.
  5. Implement Get/Set methods for all member variables.
  6. Add a member overload for the assignment operator.
  7. Add a non-member operator<< overload. Prints the values of all member variables on the given ostream.  

Part 2 – Create a GradeCollection Class

Write a class that will store a collection of Grade. This class will be used to keep track of data for multiple grades. You MUST implement ALL of the specifications below.

GradeCollection Class Specifications

  1. Create a private member variable that is an array of Grade. The size of the array can be whatever you want it to be.
  2. Your class must implement all of the following functions (use the given function prototypes):
    1. Create a default constructor that will initialize all elements of the array to default values.
    2. void Set(int index, Grade g) – Sets the value at the given index to the given Grade. You should test the index to make sure that it is valid. If the index is not valid then do not set the value.
    3. Grade Get(int index) – Return the Grade located at element index of the array.
    4. int GradeCount(double lowerBound, double upperBound) – Returns the count of the number of grades in the given range. For example, assume the following scores: 60, 70, 65, 75, 80, 90

If lowerBound is 70 and upperBound is 80 then the returned value should be 3. Any values that fall on the boundaries should be included in the count.

  1. Grade LowestGrade() – Returns the grade with the lowest score in the array.
  2. bool FindGrade(string name, Grade &g) – Returns true if the grade with the given name is in the array and false otherwise. If the grade is in the array you should copy it into the Grade reference parameter.
  3. double GradeAverage() – Returns the average of all the grades in the collection
  4. int Size() – Returns the size of the array.
  5. void Initialize() – Initializes all of the elements of the array to reasonable default values.
  6. string GetAuthor() – Returns your name. Just hard code your name into the function.

Part 3 – Main Function

In main you should create instances of the Grade and GradeCollection classes and demonstrate that ALL functions work properly on both classes. You can write unit testing code if you want but you are not required to. Make sure you call ALL functions.

Part 4 – Comments

In addition to the normal comments, EVERY function that gets updated because of the required changes should have an update comment added to the function commenting header. The update comment should have your name, the date of the change, and a short description of the change. For example:

//****************************************************

// Function: SetName

//

// Purpose: Sets the name of the grade.

//

// Update Information

// ------------------

//

// Name:

// Date: 9/20/2016

// Description: mName member variable was changed to a

//              pointer. Updated code so that it works //              with a pointer.

//

//****************************************************

Part 5 – Updated Grade and GradeCollection Classes

Grade Class Updates

The Grade class should implement all the specifications from the first assignment plus the updates and features listed below.

  1. Change all member variables to pointers. You will need to update code in any functions that use these member variables. Do NOT change any function signatures for this class. For example, assume the get/set functions have the following signatures:

std::string GetName(); void SetName(std::string name);

These signatures should remain exactly the same. The same goes for any other functions that use these member variables. Only the internal implementation of the functions will change to accommodate the use of pointers.

  1. Update the constructors. The constructors should allocate memory for the pointer member variables.
  2. Add a destructor. The destructor should deallocate memory for the pointer member variables.
  3. Update operator= and copy constructor. The operator= and copy constructor should be updated to perform deep copies.
  4. Add a non-member operator>> overload. The >> operator is used for input. Reads the values of all member variables from the given istream.

GradeCollection Class Updates

The GradeCollection class should implement all the specifications from the first assignment plus the updates and features listed below.

  1. Dynamic array. Change the internal implementation of the array so that the array is dynamically allocated.
  2. Add a size member variable to the class. This member variable should ALWAYS contain the number of elements in the array (size of the array). Some functions may cause the size of the array to change so make sure that this member variable is updated to reflect the new size.
  3. Update all the necessary code in the class so that it is usable with a dynamic array. One example of this is to change the ending condition of loops that visit all elements of the array should not be hard coded. They should use the new size variable as the ending condition.
  4. Add a one parameter constructor that takes a size. This constructor should dynamically allocate an array of the given size. It should also set the size member variable to reflect the size.
  5. Add a copy constructor. This function should make a deep copy of the passed in instance.
  6. Add a destructor. This function should perform any necessary cleanup.
  7. Add a member overload of operator= (assignment operator). This method should perform a deep copy of the passed in instance. After this function ends the size of the current instance’s array should be the same as the other instance’s array and all the data from the other instance should be copied into the current instance’s array. Hint: C++ arrays have a fixed size. You may need to delete and then reallocate memory for the current instance’s array in order to make the current instance’s array the same size as the other instance’s array. Be careful for memory leaks.
  8. Add a non-member operator<< overload. Prints the values of all elements of the array on the given ostream.
  9. Add a Resize function. Here is the function signature: void Resize(int newSize);

This function should create a new array that has the passed in size. You MUST retain any values that were previously in the array. The new array size can be larger or smaller. If the new array size is SMALLER just retain as many elements from the previous array that can fit.

Hint: C++ arrays have a fixed size. You may need to delete and then reallocate memory. Be careful for memory leaks.

  1. Add a function named Clone with the following signature:

GradeCollection *Clone();

This function should allocate a new dynamic instance of GradeCollection that is a deep copy of the current instance. This method should return a pointer to the new instance.

Hint: Any function that calls Clone is responsible for releasing the returned memory address.

Part 6 – Main Function

In main you should create instances of the updated Grade and GradeCollection classes and demonstrate that ALL functions work properly. You can write unit testing code if you want but you are not required to. Make sure you call ALL functions.

You program should not have memory leaks.

In: Computer Science

In Java, write a program that given an array A[1...n] and a value S finds 0...

In Java, write a program that given an array A[1...n] and a value S finds 0 < i < j < n such that A[i] + A[j] = S

In: Computer Science

Using C++, create a program that will input the 3 game scores of a player and...

Using C++, create a program that will input the 3 game scores of a player and then output the level of the player with a message.
 
Specifications
Prompt the user to input 3 game scores (double values).
Compute the weighted average (DO NOT JUST ADD AND DIVIDE BY 3!) score as follows:
20% for first game, 30% for second game, 50% for last game
Earlier games are worth less in the weighted average; later games are worth more.
Print the level of the player expertise based on the weighted average as follows:
average >= 2000:  expert
average is >= 1800 but is < 2000 master
average is >= 1500 but is < 1800: advanced
average is >=1000 but is < 1500: intermediate
average < 1000: beginner
For each expert player print: "Congratulations! You are an expert! "
For each player that is master or advanced print: "Good Job!"
For each player that is a beginner: "Keep on practicing!"
Run the program 2 times on the following input:
Run 1:
600 1500 900
Run 2:
1800 1500 2000

In: Computer Science

(C++) Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined...

(C++) Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. Instructions for Programming Exercise 16 of Chapter 4 have been posted below for your convenience. Exercise 16 A new author is in the process of negotiating a contract for a new romance novel.

The publisher is offering three options. In the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. In the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. In the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. The author has some idea about the number of copies that will be sold and would like to have an estimate of the royalties generated under each option. Write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. The program then outputs the royalties under each option and the best option the author could choose. (Use appropriate named constants to store the special values such as royalty rates and fixed royalties.)

An input of: 20, 5

Should have an output of:

Royalty option1: 25000.00
Royalty option2: 12.50
Royalty option3: 10.00

In: Computer Science

IP Addressing Subnet the following IP network: 160.1XY.0.0/16 (XY is the last two digits of your...

IP Addressing
Subnet the following IP network: 160.1XY.0.0/16 (XY is the last two digits of your Student ID) to
accommodate 5 subnets, each subnet will subsequently have 300, 180, 65, 30 and 4 PCs. For each subnet
find the subnet mask, network ID, broadcast IP and valid host range and complete the below table:

In: Computer Science

Please program in C++ Create two classes, HUSBAND (Family Member 1) and WIFE (Family Member 2)....

Please program in C++

Create two classes, HUSBAND (Family Member 1) and WIFE (Family Member 2). Make WIFE as friend class of HUSBAND. The structure of classes are given below.

class WIFE;

class HUSBAND

{

private:

                string Husband_fname;

                string Husband_lname;

                int Husband_income;

public:

                HUSBAND(string f1, string l1, int inc):Husband_fname(f1), Husband_lname(l1), Husband_income(inc);

                HUSBAND();

                {

                //            Default initializations of data members

                }

                int getIncome();

               

};

class WIFE

{

private:

                string Wife_fname;

                string Wife_lname;

                int Wife_income;

                int tax_rate;

public:

                WIFE(string f2, string l2, int inc, int tr) ;

                WIFE()

                {

                                //Default initializations of private data members;

                }

                float calcTax(HUSBAND &f);

               

                float getTaxRate();

               

                int getIncome();

               

};

int main()

{

                HUSBAND obj1("Albert","John",55026);

                WIFE obj2("Mary","Chin",120000,5);

//Task1: Display the tax rate;

// Task2: Display income of HUSBAND;

// Task3: Display income of WIFE;

// Task4: Display total family income;

// Task5: Display total Tax Amount;

                system("pause");

                return 0;

}

In: Computer Science

Question ::: A Forgetful Turing Machine (FTM) operates just like a normal Turing Machine except that,...

Question ::: A Forgetful Turing Machine (FTM) operates just like a normal Turing Machine except that, in every instruction (it, transition) the  letter written in the tape cell is always the letter 'a', regard less of the current state and the current letter (although the read/write head is still allowed to move either Left or Right, according to the instruction). What class of the languages is recognised by FTMs? Justify the answer.

Could u explain why it is regular language?

In: Computer Science

Java round robin scheduling algorithm: 10 processes arrive at the same time and the time that...

Java round robin scheduling algorithm:
10 processes arrive at the same time and the time that each requires is random. Show that the output of the original list and list as it changes all the way until nothing is left in the array. Using only main method and not any additional static methods and Only using scanner, arrays, and for looper while/do while loops. No array lists or other methods in java.

In: Computer Science

method to remove all elements frrom my linked list (java)

method to remove all elements frrom my linked list (java)

In: Computer Science

Hello this is an intro to CS course. The question is: Using Java, write a program...

Hello this is an intro to CS course. The question is:

Using Java, write a program that asks the user to enter three numbers. Then passes these numbers to the following methods and prints out the numbers returned by these methods.

  1. largest() – returns the largest of the three numbers
  2. smallest() – returns the smallest of the three numbers
  3. median() – returns the median of the three numbers

Example output is given below:

Enter three numbers

10

4

16

The largest is 16

The smallest is 4

The median is 10

In: Computer Science

C++ (With main to test) 2.2 Task 1 You are going to implement a variant of...

C++ (With main to test)

2.2
Task 1
You are going to implement a variant of the standard linked list, the doubly linked list.
Doubly linked lists are because they enable a backwards and forwards traversal of the
list through the addition of more pointers. By increasing the memory cost of the list, it
enables a better access since the list does not need to be traversed in only one direction.
This will consist of implementing two classes: dLL and item.


2.2.1
dLL
The class is described according to the simple UML diagram below:
2dLL<T>
-head: item<T>*
-tail: item<T>*
-size: int
----------------------------
+dLL()
+~dLL()
+getHead(): item<T>*
+getTail(): item<T>*
+push(newItem:item<T>*):void
+pop():item<T>*
+peek():item<T>*
+getItem(i:):item<T> *
+maxNode():T
+getSize():int
+printList():void
The class variables are as follows:
• head: The head pointer of the doubly linked list.
• tail: The tail pointer of the doubly linked list.
• size: The current size of the doubly linked list. This starts at 0 and increases as the
list grows in size.
The class methods are as follows:
• dLL: The class constructor. It starts by setting the variables to null and 0 respec-
tively.
• ∼dLL: The class destructor. It will deallocate all of the memory in the class.
• getHead: This returns the head pointer of the doubly linked list.
• getTail: This returns the tail pointer of the doubly linked list.
• push: This adds a new item to the doubly linked list, by adding it to the front of
the list. The push should add to the front, which refers to the head pointer.
• pop: This returns the top item of the linked list. The item is returned and removed
from the list.
• peek: This returns the top item of the linked list but without removing it from the
list.
• getItem: This returns the item of the linked list at the index specified by the
argument but without removing it from the list. If the index is out of bounds,
return null. Use 0-indexing for the get item. That is, indices start at 0.
• maxNode: This returns the value of the item that has the highest value in the linked
list.
3• getSize: This returns the current size of the linked list.
• printList: This prints out the entire list in order, from head to tail. Each item’s
data value is separate by a comma. For example: 3.1,5,26.6,17.3. Afterwards, print
out a newline.
2.2.2
item
The class is described according to the simple UML diagram below:
item <T>
-data:T
-------------------
+item(t:T)
+~item()
+next: item*
+prev: item*
+getData():T
The class has the following variables:
• data: A template variable that stores some piece of information.
• next: A pointer of item type to the next item in the linked list.
• prev: A pointer of item type to the previous item in the linked list.
The class has the following methods:
• item: This constructor receives an argument and instantiates the data variable with
it.
• ∼item: This is the destructor for the item class. It prints out ”Item Deleted” with
no quotation marks and a new line at the end.
• getData: This returns the data element stored in the item.


You will be allowed to use the following libraries: cstdlib,string,iostream.

In: Computer Science

In C++ Question 1) Theoretical Questions 1.1) Why is it better to store the tail pointer...

In C++

Question 1) Theoretical Questions

1.1) Why is it better to store the tail pointer rather than the head pointer in a circular singular linked list?

1.2) What are the main advantages of a doubly linked list compared to a singularly linked list?

Question 2) Practical Questions

Suppose a doubly-linked list makes use of a class called DLNode, defined as follows:

template<class T>

struct DLNode

{

T data;

DLNode<T> * next;

DLNode<T> * prev;

};

Further suppose the linked list class maintains a pointer to the first node in the list as a member variable called DLNode<T> *head.

2.1) Suppose left and right are variables of type DLNode<int>* pointing to two nodes that are adjacent in a doubly-linked list, i.e left->next points to right. Both nodes have predecessors and successors in the list. Write the code taht will swap the nodes in the list by adjusting pointers. Do not change the value of the data field of either nodes.

2.2) Given a circular doubly-linked list of 5 integers (1,2,3,4,5), write a function printAll() to output the list in the following order: (1,5,2,4,3). The function should work on any odd number of nodes.

In: Computer Science

5) Write a JavaScript script that will ask the user to enter in the length of...

5) Write a JavaScript script that will ask the user to enter in the length of the side of a
cube. (all the sides of a cube are equal) Based on the value that is entered by the user
from the keyboard, calculate each of the following and assign your results to variables.
1. volume of the cube
2. surface area of the cube
3. volume of the largest sphere that could fit in the box.
4. surface area of the largest sphere that could fit in the box.
5. volume of the space in between the cube and the sphere.
HINT: the largest sphere that could fit in the box will have a diameter equal to the side
of the cube.
ANOTHER HINT: to find the volume in between the cube and sphere you should subtract
volumes. in case you forgot the sphere formulas, they are:
volume of sphere = 4/3 Pi r3
surface area of sphere = 4 Pi r2
Your script should output HTML text that displays the results of your calculations.

In: Computer Science

(Please write in C++) Write a program that reads in a line consisting of a student’s...

(Please write in C++) Write a program that reads in a line consisting of a student’s name, Social Security number, user ID, and password. The program outputs the string in which all the digits of the Social Security number and all the characters in the password are replaced by x. (The Social Security number is in the form 000-00-0000, and the user ID and the password do not contain any spaces.) Your program should not use the operator [ ] to access a string element. Use the appropriate functions described in Table 7-1 below.

Expression
strVar.at(index)
strVar[index]
strVar.append(n, ch)
strVar.append(str)
strVar.clear()
strVar.compare(str)
strVar.empty()
strVar.erase()
strVar.erase(pos, n)
strVar.find(str)
strVar.find(str, pos)
strVar.find_first_of(str, pos)
strVar.find_first_not_of(str, pos)
strVar.insert(pos, n, ch)
strVar.insert(pos, str)
strVar.length()
strVar.replace(pos, n, str)
strVar.substr(pos, len)
strVar.size()
strVar.swap(str1)

With an input of: John Doe 333224444 DoeJ 123Password

The results should be: John Doe xxxxxxxxx DoeJ xxxxxxxxxxx

In: Computer Science