Questions
Write a C++ program that asks for the name and age of three people.   The program...

Write a C++ program that asks for the name and age of three people.   The program should then print out the name and age of each person on a separate line from youngest to oldest.

Hint: Start with a program that just asks for the names and ages then prints them out in the same order they are entered. Then modify the program so it prints out the list of names in every possible order.    Note that one of these will be the correct result. Then add conditions to each set of results so that only one set of results is true.

For example; part of my program will print:

name2
name1 

name3

Therefore the condition for this output would be:  (age2 < age1) && (age2 < age3) && (age1 < age3)

You can assume that all three ages will be different but consider what your program would do if two or more ages were the same. (If your program is written correctly - it should not matter)

Use if, else if and else statements in order to minimize the total number of comparisons. (See Rubric for how you will be graded on use of conditionals)

HINT: Plan out you approach ahead of time. Use pseudocode or flow chart if that helps.

Example Output:

Peter   2
Paul    20
Mary    54

In: Computer Science

4. Consider the following two alternative ER designs: • a ternary relationship set R that relates...

4. Consider the following two alternative ER designs:

• a ternary relationship set R that relates entity sets A, B, and C.

• a design in which R is replaced by an entity set E with E related to A, B, and C by 3 binary relationship sets RA, RB and RC , respectively.

Explain why, as stated, these two may not be equivalent. Then explain what could be done to make them equivalent by fixing each of RA, RB and RC , to be 1-1. m-m, 1-m, or m-1.

In: Computer Science

IN PYTHON Complete the following tasks, either in a file or directly in the Python shell....

IN PYTHON

Complete the following tasks, either in a file or directly in the Python shell.

  1. Using the string class .count() method, display the number of occurrences of the character 's' in the string "mississippi".

  1. Replace all occurrences of the substring 'iss' with 'ox' in the string "mississippi".

  1. Find the index of the first occurrence of 'p' in the string "mississippi".

  1. Determine what the following Python function does and describe it to one of your Lab TAs :

def foo(istring):

    p = '0123456789'

    os = ''

    for iterator in istring:

        if iterator not in p:

            os += iterator

    return os

In: Computer Science

I need this Java code translated into C Code. Thank you. //Logical is the main public...

I need this Java code translated into C Code. Thank you.

//Logical is the main public class

public class Logical {
public static void main(String args[]) {
char [][] table= {{'F','F','F'},{'F','F','T'},{'F','T','F'},{'F','T','T'},{'T','F','F'},{'T','F','T'},{'T','T','F'},{'T','T','T'}};

// table contains total combinations of p,q,& r
int totalTrue, totalFalse, proposition;
  
//proposition 1:

proposition=1;
start(proposition);
totalTrue=0;
totalFalse=0;
for(int i=0;i<8;i++)
{
  
{
char o= conjuctive(implecation(negation(table[i][0]),table[i][1]),implecation(table[i][2],table[i][0]));
System.out.println(" "+table[i][0]+" "+table[i][1]+" "+table[i][2]+" "+o);
if(o=='T')
totalTrue++;
else
totalFalse++;
  
}
}
finalOutput(totalTrue,totalFalse,proposition);
System.out.println(" ");
System.out.println(" ");
  

//proposition 2:
proposition=2;
start(proposition);
totalTrue=0;
totalFalse=0;
for(int i=0;i<8;i++)
{
  
{
char o= conjuctive(disjunctive(table[i][0],negation(table[i][1])),disjunctive(table[i][2],negation(implecation(table[i][0],table[i][1]))));
System.out.println(" "+table[i][0]+" "+table[i][1]+" "+table[i][2]+" "+o);
if(o=='T')
totalTrue++;
else
totalFalse++;
  
}
}
finalOutput(totalTrue,totalFalse,proposition);
System.out.println(" ");
System.out.println(" ");
  

//Proposition 3
proposition=3;
start(proposition);
totalTrue=0;
totalFalse=0;
for(int i=0;i<8;i++)
{
  
{
char o= implecation(table[i][0],implecation(negation(conjuctive(table[i][0],negation(table[i][1]))),conjuctive(table[i][0],table[i][1])));
System.out.println(" "+table[i][0]+" "+table[i][1]+" "+table[i][2]+" "+o);
if(o=='T')
totalTrue++;
else
totalFalse++;
  
}
}
finalOutput(totalTrue,totalFalse,proposition);
System.out.println(" ");
System.out.println(" ");
  

//Proposition 4
proposition=4;
start(proposition);
totalTrue=0;
totalFalse=0;
for(int i=0;i<8;i++)
{
  
{
char o= conjuctive(conjuctive(table[i][0],implecation(table[i][0],table[i][1])),negation(table[i][1]));
System.out.println(" "+table[i][0]+" "+table[i][1]+" "+table[i][2]+" "+o);
if(o=='T')
totalTrue++;
else
totalFalse++;
  
}
}
finalOutput(totalTrue,totalFalse,proposition);
  
/* //Proposition 0
proposition=0;
start(0);
totalTrue=0;
totalFalse=0;
for(int i=0;i<8;i++)
{
  
{
char o= conjuctive(table[i][0],conjuctive(table[i][1],negation(table[i][2])));
System.out.println(" "+table[i][0]+" "+table[i][1]+" "+table[i][2]+" "+o);
if(o=='T')
totalTrue++;
else
totalFalse++;
  
}
}
finalOutput(totalTrue,totalFalse,proposition);*/
  
}

//method to check contradiction & tautology
static public void finalOutput(int totalTrue,int totalFalse,int proposition)
{
System.out.println(" "+totalTrue+" combination result in Proposition " +proposition+" being T");
System.out.println(" "+totalFalse+" combination result in Proposition "+proposition+ " being F");
if(totalTrue==8)
System.out.println(" Proposition "+ proposition+ " is a tautology");
else if(totalFalse==8)
System.out.println(" Proposition " + proposition+" is a contradiction");
else
System.out.println(" Proposition "+proposition +" is neither a tautology nor a contradiction");
}
static public void start(int i)
{
System.out.println(" "+"p"+" "+"q"+" "+"r"+" "+"Proposition "+ i);
System.out.println("----------------------------------------------------");
}
// negation method
static public char negation(char x)
{
if(x=='T')
return 'F';
else
return 'T';
}
// disjuctive method
static public char disjunctive(char x, char y)
{
if(x=='T' || y=='T')
return 'T';
else
return 'F';
}
// conjuctive method
static public char conjuctive(char x, char y)
{
if(x=='F' || y=='F')
return 'F';
else
return 'T';
}
// implecation method
static public char implecation(char x,char y)
{
if((x=='T' && y=='T') ||(x=='F' && y=='F') || (x=='F' && y=='T'))
return 'T';
else
return 'F';
}
}

In: Computer Science

Create a two-part form that calculates weekly income for Happy Diner's waitress Tammy, based on her...

Create a two-part form that calculates weekly income for Happy Diner's waitress Tammy, based on her regular hours, overtime pay, and tips. She makes $10 an hour, if she works 40 hours a week, or less. Her overtime pay is $15 an hour. If Tammy worked over 40 hours, she is earning her overtime wages. Happy customers give her tips as well.

Use an HTML document named tipsYourlastname.html as a Web form with two text boxes — one for the number of hours worked and one for the tips. Use a PHP document named tipsyourlastname.php as the form handler. Output the total amount earned to the screen in some nice organized manner. Please comment your code appropriately and test your program with various input to ensure it operates correctly. Check your math as well.

Please remember that program has to work to get credit.  This is a very small program, but you need to plan ahead and give yourself enough time for testing and debugging. Write a small piece of code at a time and test it before you add more code. Work incrementally.

In: Computer Science

" line 48"     return delta.days     ^ SyntaxError: 'return' outside function import datetime def nowDate():...

" line 48"
    return delta.days
    ^
SyntaxError: 'return' outside function

import datetime


def nowDate():
    current_time = datetime.datetime.now()
    new_time = datetime.datetime(
        current_time.year,
        current_time.month,
        current_time.day,
        0,
        0,
        0,
        )
    return new_time


def plusOneDay(daytime):
    tomorrow = daytime + datetime.timedelta(days=1)
    return tomorrow


def nDaystoHoliday():
    NJCU_holidays = [
        (datetime.date(2019, 1, 1), "New Year's Day"),
        (datetime.date(2019, 1, 21), 'Martin Luther King, Jr. Day'),
        (datetime.date(2019, 2, 19), "President's Day"),
        (datetime.date(2019, 4, 19), 'Good Friday'),
        (datetime.date(2019, 5, 27), 'Memorial Day'),
        (datetime.date(2019, 7, 4), 'Independence Day'),
        (datetime.date(2019, 9, 2), 'Labor Day'),
        (datetime.date(2019, 10, 14), 'Columbus Day'),
        (datetime.date(2019, 11, 11), "Veteran's Day"),
        (datetime.date(2019, 11, 28), 'Thanksgiving'),
        (datetime.date(2019, 12, 25), 'Christmas Day'),
        ]


now = datetime.datetime.now().date()
print (now)
date = NJCU_holidays[0][0]
print (date)
for i in range(1, len(NJCU_holidays)):
    holiday = NJCU_holidays[i][0]
    delta = holiday - now
    if(delta.days > 0):
      return delta.days

time = nowDate()
plusOneDay(time)
nDaystoHoliday()

In: Computer Science

Continue performing the steps in this appendix, starting with the section called Developing the Schedule. Print...

Continue performing the steps in this appendix, starting with the section called Developing the
Schedule. Print out the following screens or send them to your instructor, as directed:
a. Figure A-32. All task durations and recurring task entered
b. Figure A-39. Network diagram view
c. Figure A-46. Changing Work hours for tasks
d. Figure A-56. Earned value report
e. Continue performing the steps, or at least read them. Write a one-to-two page paper
describing the capabilities of Project Professional 2016 and your opinion of this software.
What do you like and dislike about it?

In: Computer Science

Write a program that will input the information for 2 different employees. Prompt the user for...

Write a program that will input the information for 2 different employees. Prompt the user for the first employee’s name, hours worked and rate. Compute the salary and display it. Do the same for the second and third employees. Then, display a message to the effect that the highest salary is whatever and the lowest salary is whatever. When the program runs, the following should display information should line up just as I have it below. E:\> java Quiz4 Name:

John Doe Class: CSCI 1250-001 (or 002) Date: September 18, 2019 Program: Quiz4.java First Employee:

John Smith Hours Worked: 40.0 Rate of pay: 10.0 Salary for John Smith is $400.00

Second Employee:

Sarah Jones Hours worked: 30.0 Rate of pay: 7.50 Salary for Sarah Jones is $225.00

Third Employee: Andrew Johnson Hours Worked: 31.5 Rate of pay: 10.75 Salary for Andrew Johnson is $338.63

The largest salary is $400.00 The smallest salary is $225.00

In: Computer Science

Given this class: class Issue { public:                 string problem; int howBad; void setProblem(string problem); };...

Given this class:

class Issue

{

public:

                string problem;

int howBad;

void setProblem(string problem);

};

And this code in main:

vector<Issue> tickets;

Issue issu;

a)

tickets.push_back(-99);

State whether this code is valid, if not, state the reason

b)

Properly implement the setProblem() method as it would be outside of the class. You MUST name the parameter problem as shown in the prototype like:

(string problem)

c)

Write code that will output the problem attribute for every element in the tickets vector. The code MUST work for no matter how many elements are contained in tickets. The output should appear as:

Problem #1 is the problem attribute in element 1.

Problem #2 is the problem attribute in element 2.

In: Computer Science

Write a java code to demonstrate the File IO. Your code should get the following information...

Write a java code to demonstrate the File IO. Your code should get the following information from the user.

• Get a file name fname for output • Get number of data (numbers) (N) you want to process from the user

• Get N numbers from the users through keyboard and store them in an array

• Get M (How many numbers to read from file)

• (Or)You are free to use same N for M (use N for both purposes) You have to define two methods:

1) To write the numbers from the array into the file fname

2) To read numbers from the file fname, store them in an array, and compute average of the numbers.

The method should display the numbers from the array and the average value.

In: Computer Science

Please identify each of the requirements as a functional requirement/property or non-functional requirement/property. For every non-functional...

Please identify each of the requirements as a functional requirement/property or non-functional requirement/property. For every non-functional property/requirement, please add a remark to explain why.

1. Customers must provide shipping information.

2. The system allows customers to pay with a Pay Pal account or a valid credit card on a web browser of their choice.

3. Customers must first register and set up an account with the system before they can purchase items.

4. In order to register an account, customers must have a valid e-mail address.

5. Customers must create a password and provide personal answers to account security questions.

6. Customers may have their credit card information saved to their account for faster use in the future.

7. Customers have the choice of splitting up a payment into multiple smaller payments.

8. Once an order is completed, the customer receives a confirmation number.

9. Upon receipt of the payment, the confirmed order is assigned with a tracking number.

10. The bookstore manager will be able to access the system in order to view sales summary reports.

In: Computer Science

What can be said about baseline data and ABABA design

What can be said about baseline data and ABABA design

In: Computer Science

**Only need the bold answered In Java, implement the Athlete, Swimmer, Runner, and AthleteRoster classes below....

**Only need the bold answered

In Java, implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class must be in separate file. Draw an UML diagram with the inheritance relationship of the classes.

1. The Athlete class
a. All class variables of the Athlete class must be private.

b.is a class with a single constructor: Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender). All arguments of the constructor should be stored as class variables. There should only be getter methods for first and last name variables. There should be no getters or setters for birthYear, birthMonth, birthDay.

c. Getter and setter methods for the gender of the athlete. The method setGender accepts a character and store it as a class variable. Characters 'm', 'M' denotes male, 'f' or 'F' denotes male or female. Any other char will be treated as undeclared. The method getGender return either the word "male" or "female" or “undeclared”.

  1. The method computeAge() takes no arguments and returns the athletes computed age (as of today's date) as a string of the form "X years, Y months and Z days". Hint: Use the LocalDate and Period classes.

    i. e.g. "21 years, 2 months and 3 days". ii. e.g. "21 years and 3 days".

    iii. e.g. "21 years and 2 months". iv. e.g. "21 years".

    v. e.g. "2 months and 3 days".

  2. The method public long daysSinceBirth() takes no arguments and returns a long which is the number of days since the athlete’s date of birth to the current day. Hint: Use the LocalDate and ChronoUnit classes.

  3. The toString method returns a string comprised of the results ofgetFname, getLName and computeAge. E.g.

    i. “Bunny Bugs is 19 years and 1 day old”

  4. The equals method returns true if the name and date of birth of this athlete and the compared other athlete are the same, otherwise return false.

2. The Swimmer class
a. All class variables of the Swimmer class must be private.

  1. inherits from the Athlete class and has a single constructor,

    Swimmer(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender, String team). There should be a class variable for team. There should be a getter method for team.

  2. The Swimmer class stores swim events for the swimmer. There should be a class variable for events. A swimmer participates in one or more of these events. The addEvent method is oveloadedand either adds a single event for the swimmer public boolean addEvent(String singleEvent) or adds a group of events for the swimmer public boolean addEvent(ArrayList multiEvents). Each event is of type String. Duplicate events are not stored and return false if duplicate found.

  3. There should be a getter method that returns the class variable events.

  4. The overridden toString method returns a string comprised of the concatenation of the parent’s toString return plus " and is a swimmer for team: XXXXX in the following events: YYYYY; ZZZZZZ." E.g.

    i. “Missy Franklin is 24 years and 4 months old and is a swimmer for team: Colorado Stars. She participates in the following events: [100m freestyle, 100m backstroke, 50m backstroke]”

3. The Runner class
a. All class variables of the Runner class must be private.

  1. inherits from the Athlete class and has a single constructor,

    Runner(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender, String country). There should be a class variable for country. There should be a getter method for country.

  2. The Runner class stores race events for the runner. There should be a class variable for events. Each event is a Distance. The list of valid events is given below:
    M100, M200, M400, M3000, M5000, M10000. A runner participates inone or more of these events. The addEvent method is oveloadedand either adds a single event for the runner public boolean addEvent(String singleEvent) or adds a group of events for the runner public boolean addEvent(ArrayList multiEvents). Each event is of type String. Duplicate events are not stored and return false if duplicate found.

  1. There should be a getter method that returns the class variable events.

  2. The toString method returns a String in the form: " AAA BBBB is XX years, YY months and ZZ days. He is a citizen of CCCCCCC and is a DDDDDDDD who participates in these events: [MJ00, MK00, ML00]”. If she does not participate in M3000 or M5000 or M10000 then she is a sprinter. If she does not participate in M100 or M200 or M400 then she is a long-distance runner. Otherwise she is a super athlete. E.g.

    i. “Bunny Bugs is 19 years and 1 day old. His is a citizen of USA and is a long-distance runner who participates in these events: [M10000]”

4. The AthleteRoster class
a. All class variables of the AthleteRoster class must be private.

  1. Does not inherits from the Athlete class. The AthleteRoster class has a single constructor, AthleteRoster(String semster, int year). There should be class variables for semester and year. There should be getter methods for semester and year.

  2. The AthleteRoster class has only one method for adding Athlete to the roster, by using the boolean addAthlete(Athlete a)method. The method returns true if the athlete was added successfully, it returns false if the athlete object already exists in the roster and therefore was not added.

  3. Your AthleteRoster class will have only one class level data structure, an ArrayList, for storing athlete objects.

  4. The String allAthletesOrderedByLastName() method returns a string object with of all the names of the athletes (Swimmers, Runners, etc.) in ascending order of last names(a-z).

  5. The String allAthletesOrderedByAge() method returns a string object with of all the names of the athletes (Swimmers, Runners, etc.) in descending order of age(100-0).

  6. The String allRunnersOrderedByNumberOfEvents() method returns a string object with of all the names of the Runners only in ascending order of number of events they participate in (0-100).

Here is the driver:

import java.util.ArrayList;
import java.util.Arrays;

public class AthleteDriver {
   public static void main(String args[]) {

       //Check Athlete Class
       Athlete a1 = new Athlete("Daffy","Duck", 2000, 9, 7,'j'); System.out.println("Gender is "+a1.getGender());//undeclared
       a1.setGender('F');
       System.out.println("Gender is "+a1.getGender());//female
       a1.setGender('m');
       System.out.println("Gender is "+a1.getGender());//male
       System.out.println("ComputeAge method says "+a1.computeAge());
       System.out.println("First name is : "+a1.getFname()); //Daffy
       System.out.println("DaysSinceBirth method says "+a1.daysSinceBirth()+" days"); System.out.println("Last name is : "+a1.getLname()); //Duck
       System.out.println("Output of our toString correct?: \n"+a1);
       System.out.println("=======================================\n");

       //Check Runner Class
       Runner r5 = new Runner("Bugs","Bunny", 2000, 9, 8, 'm',"USA");
       System.out.println("Did we add M10000 successfully?: "+r5.addEvent("M10000")); //true
       System.out.println("Did we unsucessfully try to add M10000 again?: "+r5.addEvent("m10000")); //false
       ArrayList<String> temp = new ArrayList<String>(Arrays.asList("M100", "M3000"));
   System.out.println("Did we successfully add mutiple events?: "+r5.addEvent(temp));//true
       System.out.println("Did we unsucessfully try to add mutiple events?: "+r5.addEvent(temp));//false
       System.out.println("How many events does Bugs participate in?: "+r5.getEvents().size());//3
       System.out.println("Gender is "+r5.getGender());//male
       System.out.println("Output of our toString correct?: \n"+r5);
       System.out.println("=======================================\n");

       //Check Swimmer Class
       Swimmer s1 = new Swimmer("Franklin", "Missy", 1995, 5, 10, 'F', "Colorado Stars");
       System.out.println("Did we add 100m backstoke successfully?: "+s1.addEvent("100m backstoke")); //true
       System.out.println("Did we unsucessfully try to add 100m backstoke again?: " +s1.addEvent("100M Backstoke")); //false
       temp = new ArrayList<String>(Arrays.asList( "200m backstoke","200m freestyle"));
       System.out.println("Did we successfully add mutiple events?: "+s1.addEvent(temp));//true
       System.out.println("Did we unsucessfully try to add mutiple events?: "+s1.addEvent(temp));//false
       System.out.println("How many events does s1 participate in?: "+s1.getEvents().size());//4 System.out.println("Gender is "+s1.getGender());//female
       System.out.println("Output of our toString correct?: \n"+s1);
       System.out.println("=======================================\n");

       //Check AthleteRoster
       Swimmer s2 = new Swimmer("Ruele", "Naomi", 1997, 1, 13, 'F',"Florida International University");
   //   s2.addEvent(newArrayList<String>(Arrays.asList("100m backstoke","50m backstoke","100m freestyle")));

   //   Runner r1 = new Runner("Bolt", "Usain", 1986, 8, 21, 'M',"Jamaica");
//       r1.addEvent("M100"); r1.addEvent("M200");

   //   Runner r2 = new Runner("Griffith", "Florence", 1959, 12, 21, 'F',"United States of America"); r2.addEvent("M100"); r2.addEvent("M200");
   //   r2.addEvent("M400"); r2.addEvent("M10000"); r2.addEvent("M3000");
   //   r2.addEvent("M5000");

   //   AthleteRoster ar = new AthleteRoster("Fall",2019);
   //   ar.addAthlete(a1);
   //   ar.addAthlete(s1);
   //   ar.addAthlete(r1);
   //   ar.addAthlete(r2);
   //   ar.addAthlete(s2);
   //   ar.addAthlete(r5);
   //   System.out.println(ar.allRunnersOrderedByNumberOfEvents());
       System.out.println("=======================================\n");

   //   System.out.println(ar.allAthletesOrderedByAge());
       System.out.println("=======================================\n");

   //   System.out.println(ar.allAthletesOrderedByLastName());
       System.out.println("=======================================\n");


   }

}

Complete the code before the due date. Submission of the completed eclipse project is via github link posted on the class page. Add your UML drawing to the github repo. ________________________________________________________________________ Example output:

__________Example from AthleteDriver shown below

Gender is undeclared
Gender is female
Gender is male
ComputeAge method says 19 years and 4 days
First name is : Duck

DaysSinceBirth method says 6943 days Last name is : Daffy
Output of our toString correct?:
Duck Daffy is 19 years and 4 days old =======================================

Did we add M10000 successfully?: true
Did we unsuccessfully try to add M10000 again?: false
Did we successfully add multiple events?: true
Did we unsuccessfully try to add multiple events?: false
How many events does Bugs participate in?: 3
Gender is male
Output of our toString correct?:
Bunny Bugs is 19 years and 3 days old. His is a citizen of USA and is a super athlete who participates in these events: [M10000, M100, M3000] =======================================

In: Computer Science

Write a program in Java that reads an input text file (named: input.txt) that has several...

Write a program in Java that reads an input text file (named: input.txt) that has several lines of text and put those line in a data structure, make all lowercase letters to uppercase and all uppercase letters to lowercase and writes the new lines to a file (named: output.txt).

In: Computer Science

The problem is below. This is for an intro to Python class, so, if possible keep...

The problem is below. This is for an intro to Python class, so, if possible keep it relatively simple and 'basic.'

The code in bold below is given:

def trade_action(current_stock, purchase_price, current_price, investment):
# Write your code here.
return "Hold Shares."

Instructions:

Many investment management companies are switching from manual stock trading done by humans to automatic stock trading by computers. You've been tasked to write a simple automatic stock trader function that determines whether to buy, sell, or do nothing (hold) for a particular account. It should follow the old saying "Buy low, sell high!"

This function takes 4 input parameters in this order:

  1. current_shares - current number of shares of this stock in the account (int).
  2. purchase_price - price (per share) paid for current stock in the account (float).
  3. market_price - current market price (per share) of stock in the account (float).
  4. available_funds - maximum amount the client is willing to spend on a stock purchase (float).

Any transaction (buy or sell) costs $10. This $10 must be paid out of the available_funds for a purchase, or out of the proceeds of a stock sale. Be sure to account for this fee in your profit calculations.

A purchase would be considered profitable when the current market price is lower than the purchase price, and the available funds will allow us to buy enough shares so that the difference in value will cover the $10 transaction fee. In this case the function should return the string "Buy # shares" where # is an integer representing the number of shares to purchase.

A sale would be considered profitable when the current market price is higher than the purchase price, and the value gained by selling the shares will cover the $10 transaction fee. In this case the function should return the string "Sell # shares" where # is an integer representing the number of shares to sell.

If neither a buy nor a sell would be profitable, then the function should return the string "Hold shares."

Here are some test cases that your function should satisfy:  

Test 1 Test 2 Test 3 Test 4 Test 5 Test 6
current_shares 10 20 15 1 10 1
purchase_price 100 2 12 1 1 1
market_price 1 1 1 11 3 12
available_funds 10 21 12 0 30 0
OUTPUT Hold shares Buy 11 shares Buy 2 shares HoldShares Sell 10 shares Sell 1 shares

Rationale for test cases:

Test 1
Even though the current market price is very low (compared to the purchase price), after paying the $10 transaction fee, we would not have any funds left to buy shares; so we can only hold.

Test 2
After paying the $10 transaction fee, there are enough funds remaining to buy 11 shares. At a purchase_price vs. market_price difference of $1 per share, our 11 shares represent a value gain of $11 dollars, which is $1 more than the $10 transaction fee - so we come out $1 ahead.

Test 3
After paying the $10 transaction fee, there are enough funds remaining to buy 2 shares. At a purchase_price vs. market_price difference of $11 per share, our 2 shares represent a value gain of $22 dollars, which is $12 more than the $10 transaction fee - so we come out $12 ahead.

Test 4
Selling our 1 share for $11 will leave us with just $1 after we pay the $10 transaction fee. That is the same as what we paid for it, and we won't make any profit - so we should hold.

Test 5
With a market_price vs. purchase_price vs. difference of $2 per share, we stand to make $20 from the sale of our 10 shares. This is $10 more than the price of the transaction fee, so we will come out $10 ahead - therefore we should sell all 10 shares.

Test 6
Our 1 share is worth $11 more than we paid for it at the current market price. The $11 dollars obtained by selling that share now will still leave us with a profit of $1 after paying the $10 transaction fee. Profit is profit, so we should sell.

Things to think about when you’re designing and writing this program:

  1. Look for opportunities to use variables as a way to name things, and to break larger more complex expressions down into simpler expressions.
  2. Spend some time choosing your names carefully. Names should be descriptive.
  3. Try to design and write your code a few lines at a time. Design and write a few lines, then run some tests to see if these lines are doing what you want them to do. If they are not, then analyze and correct them before you move on to the next few lines of code.

In: Computer Science