Using Python, write a program named hw3a.py that meets the following requirements:
In: Computer Science
How can I improve my code below to meet the requirements of this assignment with syntax add to my code to complete the assignment below:
#include <iostream>
#include <vector>
using namespace std;
class Inventory {
private:
int itemNumber;
int quantity;
double cost;
double totalCost;
public:
Inventory() { itemNumber = 0; quantity = 0; cost = 0; totalCost =
0; }
Inventory(int n, int q, double c) {
itemNumber = n; quantity = q; cost = c; setTotalCost();
}
void setItemNumber(int n) {
itemNumber = n;
}
void setCost(double c) {
cost = c;
}
void setQuantity(int q) {
quantity = q;
}
void setTotalCost() {
totalCost = quantity * cost;
}
int getItemNumber() const {
return itemNumber;
}
int getQuantity() const {
return quantity;
}
double getCost() const {
return cost;
}
double getTotalCost() const {
return totalCost;
}
};
class CashRegister {
private:
Inventory Inv;
int itemNumber;
int quantity;
double cost;
public:
CashRegister(Inventory& temp, int q) {
itemNumber = temp.getItemNumber();
quantity = q; cost = temp.getCost();
temp.setQuantity(temp.getQuantity() - q);
} //constructor
CashRegister() {
itemNumber = 0; quantity = 0; cost = 0; Inv.setItemNumber(0);
Inv.setQuantity(0); Inv.setCost(0);
}
double getUnitPrice() const { return 1.3 * cost; }
double getSubTotal() const { return 1.3 * cost * quantity; } //
unitprice * qty
double getTax() const { return 1.3 * cost * quantity * .06; } //
subtotal*.06
double getTotal() const { return 1.3 * cost * quantity * 1.06; } //
subtotal plus 6% tax
};
int main()
{
int q;
int n;
int pause;
const int MAX_INV_SIZE = 5;
vector <Inventory> Inv(MAX_INV_SIZE);
Inv[0].setItemNumber(0);
Inv[0].setQuantity(10);
Inv[0].setCost(4.34);
Inv[1].setItemNumber(1);
Inv[1].setQuantity(5);
Inv[1].setCost(9.20);
Inv[2].setItemNumber(2);
Inv[2].setQuantity(100);
Inv[2].setCost(3.00);
Inv[3].setItemNumber(3);
Inv[3].setQuantity(12);
Inv[3].setCost(.5);
Inv[4].setItemNumber(4);
Inv[4].setQuantity(18);
Inv[4].setCost(1);
cout << "Welcome to the Cash register program...." <<
endl;
cout << "Which item would you like to purchase? " <<
endl;
cout << "1. Adjustable Wrench" << endl;
cout << "2. Screwdriver" << endl;
cout << "3. Pliers" << endl;
cout << "4. Ratchet" << endl;
cout << "5. Socket Wrench" << endl;
cin >> n;
while (n > 5 || n < 1) { cout << "Invalid entry...try
again: "; cin >> n; }
n--;
cout << "Enter the quantity purchased: "; cin >>
q;
while (q < 0) { cout << "We don't sell negative # of
items...try again: "; cin >> q; }
CashRegister C(Inv[n], q);
cout << "Subtotal: " << C.getSubTotal() <<
endl;
cout << "Tax: " << C.getTax() << endl;
cout << "Total: " << C.getTotal() << endl;
cout << "Items left: " << Inv[n].getQuantity();
cin >> pause;
}
Cash Register Basic Steps in Creating your Program
1. Plan your logic before working on the project and review the syntax you will use in the project. Think about how you want the lines of output to be displayed to the user. You will want to tell the user what the program does and what type of input you expect from the user (Introduction to the User). Select names of the variables you will use in the program.
2. Create a C++ project in Visual Studio 2012. And have the code window open to write the project code. Display Using Visual Studio to create your program in C++ and follow the instructions on creating the project. Declare variables to hold information about tank capacity and mpg
Set up information about this program and what the user will enter and results expected
Ask the user to enter some information requested and save the response to a variable. Make sure the position for the user to enter information is on the same line as the request for information.
Use line spacing (endl or \n) to separate lines of output to make it easy for the user to read the information.
3. Documentation: All lines of code must be documented.
Use the syntax to designate lines in code as comments (//)
These comments can be at the end of a line of code or in a group definition at the beginning of a section of code. All methods and function need a group heading document.
4. Run the program using Ctrl+F5. Debug the code, making sure all calculations are correct and the line spacing is suitable for readability.
Your program Assignment Design a CashRegister class that can be used with the Inventory Item class discussed in the chapter.
The CashRegister class should perform the following:
1. Ask the user for the item and quantity being purchased.
2. Get the item’s cost from the Inventory Item object.
3. Add a 30% profit to the cost to get the item’s unit price.
4. Multiply the unit price times the quantity being purchased to get the purchase subtotal.
5. Compute the 6% sales tax on the subtotal to get the purchase total.
6. Display the purchase subtotal, tax and total on the screen
7. Subtract the quantity being purchased from the on Hand variable of the Inventory Item class object. Implement both classes in a complete program. Feel free to modify the Inventory Item class in any way necessary. Be sure and loop the program so that multiple items can be purchases Input Validation: Do not accept a negative value for the quantity of items being purchased.
In: Computer Science
(in C# please.) EXCEPTION HANDLING Concept Summary:
1. Use of try… catch in a program
2. Define an exception class and call it from the driver program.
For this lab you will complete two parts.
Part (a) of the lab implements try… catch and uses an existing exception in C# or in Java.
Write a program that implements an ArrayIndexOutOfBounds error.
Part (b) writes a program that converts a time from 24-hour notation to 12-hour notation.
Assume the user will enter the time as a 4-digit number with no colon.
Submission Guidelines: You will turn in 3 program files. Part (a) has one program file Part (b) requires two program files. (Note: C# Students can turn in one program file)
Specifications: Part (a): Write a program in Java or C# that declares an array of 5 elements and displays the contents of the array. Your program should attempt to access the 6th element in the array (which does not exist) and using try.. catch your program should prevent the run-time error and display your error message to the user. Sample output including error message is provided below. SAMPLE OUTPUT: Part (a) Printing an element out of bounds 5 7 11 3 0 You went out of limits in the array
Part (b): Define an exception class called InvalidTimeFormatException. If the user enters an invalid time like 1065 or 2515, the program should throw and handle an InvalidTimeFormatException. NOTE: Assume the user will enter the time as a 4-digit number with no colon.
SAMPLE OUTPUT:
Part (b) Enter time in 24-hour notation: 1614
That is the same as 4:14 PM Again? (y/n) y
Enter time in 24-hour notation: 0245
That is the same as 2:45 AM Again? (y/n) y
Enter time in 24-hour notation: 1215
That is the same as 12:15 PM Again? (y/n) y
Enter time in 24-hour notation: 2612 Error: Hour can only be between 0 and 23 Again? (y/n) y
Enter time in 24-hour notation: 1562 Error: Minutes can only be between 0 and 59 Again? (y/n) n
In: Computer Science
Account
class
Create a class named
Account
, which has the following private properties:
Create a no-argument constructor that sets the number and balance to zero.
Create a two-parameter constructor that takes an account number and balance.
First, implement getters and setters:
getNumber()
,
getBalance()
,
setBalance(double newBalance)
. There is no
setNumber()
-- once an account is created, its account
number cannot change.
Now implement these methods:
void deposit(double amount)
and
void withdraw(double amount)
. For both these methods, if the
amount is less than zero, the account balance remains untouched.
For the
withdraw()
method, if the amount is greater than the
balance, it remains untouched.
Then, implement a
toString()
method that returns a string with the account
number and balance, properly labeled.
SavingsAccount
class
This class inherits from
Account
and adds a private
apr
property, which is the annual percentage rate for
interest. Write a no-argument constructor that sets the account
number, balanace, and APR to zero. Write a three-argument
constructor that takes an account number, balance, and interest
rate as a decimal (thus, a 3.5% interest rate is given as
0.035).
Modify
toString()
to include the interest rate.
Add a getter and setter method for
apr
. The setter should leave the APR untouched if given a
negative value.
Write a
calculateInterest()
method that returns the annual interest,
calculated as the current balance times the annual interest
rate.
CreditCardAccount
class
This class inherits from
Account
and adds a private
apr
property, which is the annual interest rate charged on
the balance. It also has a private
creditLimit
property (double) which gives the credit limit
for the card. Write a no-argument constructor that sets all the
properties to zero. Write a four-argument constructor that takes an
account number, balance, interest rate as a decimal (thus, a 3.5%
interest rate is given as 0.035), and credit limit. Write getters
and setters for the
apr
and
creditLimit
.
Modify
toString()
to include the interest rate and credit
limit.
Override the
withdraw()
function so that you can have a negative balance.
If a withdrawal would push you over the credit limit, leave the
balance untouched. Examples:
In short, the maximum amount you can withdraw is your current balance plus the credit limit.
Add a
calculatePayment()
method that works as follows:
Write a program named
TestAccounts
that creates an array of five
Account
objects:
Account
number 1066 with a balance of $7,500.
SavingsAccount
number 30507 with a balance of $4,500 and an
APR of 1.5%
CreditCardAccount
number 51782737 with a balance of
$7,000.00, APR of 8%, and credit limit of $1000.00
CreditCardAccount
number 629553328 with a balance of
$1,500.00, an APR of 7.5%, and a credit limit of $5,000
CreditCardAccount
number 4977201043 with a balance of
-$5,000.00, an APR of 7%, and a credit limit of $10,000Your program will use a loop to do the following for each account:
toString()
.
Here is some sample output:
Account: 1066 Balance: $4852.00 Account: 30507 Balance: $1852.00 Interest Rate: 1.50% Annual Interest: $27.78 Account: 51782737 Balance: $4352.00 Interest Rate: 8.00% Credit Limit: $1000.00 Monthly Payment: $0.00 Account: 629553328 Balance: $-1148.00 Interest Rate: 7.50% Credit Limit: $5000.00 Monthly Payment: $7.18 Account: 4977201043 Balance: $-7648.00 Interest Rate: 7.00% Credit Limit: $10000.00 Monthly Payment: $20.00
Put the
Account
,
SavingsAccount
, and
CreditCardAccount
classes in the
TestAccounts.java
file rather than creating separate files.
Please submit only one file. Upload the
TestAccounts.java
file here.
In: Computer Science
Use Python program.
stock = {
"pineapple": 6,
"peach": 0,
"tangerine": 32,
"pear": 15
}
prices = {
"pineapple": 4,
"peach": 2,
"tangerine": 1.5,
"pear": 3
}
In: Computer Science
C# Yahtzee Program
I am creating a Yahtzee program where you have the option to choose 5 or more dice that will be rolled. I just need help trying to create a random dice roll and seeding it. Could you give me some code examples of getting a dice roll of a six sided die that won't display similar results.
In: Computer Science
Write the body of the function getFileSize to return the size of an opened file.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
long getFileSize (FILE * f)
{
} int main () { FILE * file = fopen (“myfile.txt”,”r”); long fsize = getFileSize(file); printf ("File Size : %lu\n",fsize); return 0;}
In: Computer Science
In: Computer Science
programing language JAVA:
Design and implement an application that reads a sentence from the user, then counts all the vowels(a, e, i, o, u) in the entire sentence, and prints the number of vowels in the sentence. vowels may be upercase
In: Computer Science
This exercise is a bit more complicated and will be a review of what we’ve learned about lists and dictionaries. The aim of this exercise is to make a gradebook for a group of students.
Follow these steps:
students = {
"lloyd": {
"name": "Lloyd",
"homework": [90.0,97.0,75.0,92.0],
"quizzes": [88.0,40.0,94.0],
"tests": [75.0,90.0]
},
"alice": {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
},
"tyler": {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}
}
A – 100% - 90%
B – 90% - 80%
C – 80% - 70%
D – 70% - 60%
F – 59% - below
Your program should work for any list of students, i.e. your solution should be general in that it takes in any dictionary in this format of any length, process the data, and return the results. You should test it with this input, as well as input you make up. I will also test it with both this input as well as another set of data that is formatted similarly.
In: Computer Science
hi so i'm new to c++ i understand the language pretty good however no experience whatsoever with visual studio here is the assigment
Examine, understand, compile and run the FruitJuice Program (all files) and submit it (a copy is made available on LMS)
i know what the program does and i get what is doing but i don't even know if i'm opening the thing the right way from visual studio it wont see it as a project at all. here is the list of files if have.
cashRegister.h
cashRegisterImp.cpp
dispenserType.h
dispenserTypeImp.cpp
mainProgJuiceMachine.cpp
i can open every file individually with visual studio from the folder but i don't know how to open it as a project. or run it. please help
i need to open de project run it and compile it.
In: Computer Science
python 3
countries = ['mexico,'eseft,'ry,',ft,'us']
Write a statement that sorts the countries alphabetically and another statement that prints the last country in the sorted nations list.
In: Computer Science
Create a XSD Schema to validate and provide structure for the XML document below:
<?xml version="1.0" encoding="UTF-8" ?>
<forecast qTime="28/10/20 10:00 PM"
qLocation="Singapore">
<weather yyyymmdd="20200430">
<year>2020</year>
<month>04</month>
<date>30</date>
<comment>Plenty of sunshine</comment>
<code>sunny</code>
<highest>32.6</highest>
<lowest>28.4</lowest>
</weather>
<weather yyyymmdd="20200218">
<year>2020</year>
<month>02</month>
<date>18</date>
<comment>Plenty of sunshine</comment>
<code>sunny</code>
<highest>34.6</highest>
<lowest>30.5</lowest>
</weather>
<weather yyyymmdd="20200710">
<year>2020</year>
<month>07</month>
<date>10</date>
<comment>Partly sunny</comment>
<code>partlySunny</code>
<highest>33.1</highest>
<lowest>29.2</lowest>
</weather>
<weather yyyymmdd="20200616">
<year>2020</year>
<month>06</month>
<date>16</date>
<comment>Considerable clouds</comment>
<code>cloudy</code>
<highest>30.5</highest>
<lowest>25.4</lowest>
</weather>
<weather yyyymmdd="20200612">
<year>2020</year>
<month>06</month>
<date>12</date>
<comment>Cloudy with a thunderstorm</comment>
<code>thunderstorm</code>
<highest>29.1</highest>
<lowest>23.2</lowest>
</weather>
<weather yyyymmdd="20200421">
<year>2020</year>
<month>04</month>
<date>21</date>
<comment>Plenty of sunshine</comment>
<code>sunny</code>
<highest>32.2</highest>
<lowest>29.8</lowest>
</weather>
<weather yyyymmdd="20200628">
<year>2020</year>
<month>06</month>
<date>28</date>
<comment>A morning shower, then rain</comment>
<code>rain</code>
<highest>30.2</highest>
<lowest>22.7</lowest>
</weather>
<weather>
<weather yyyymmdd="20200502">
<year>2020</year>
<month>05</month>
<date>02</date>
<comment>Cloudy with a thunderstorm</comment>
<code>thunderstorm</code>
<highest>28.1</highest>
<lowest>26.9</lowest>
</weather>
<weather yyyymmdd="20200428">
<year>2020</year>
<month>04</month>
<date>28</date>
<comment>A morning shower</comment>
<code>rain</code>
<highest>28.8</highest>
<lowest>22.2</lowest>
</weather>
<weather yyyymmdd="20200410">
<year>2020</year>
<month>04</month>
<date>10</date>
<comment>Partly sunny</comment>
<code>partlySunny</code>
<highest>33.7</highest>
<lowest>29.3</lowest>
</weather>
<weather yyyymmdd="20200730">
<year>2020</year>
<month>07</month>
<date>30</date>
<comment>Plenty of sunshine</comment>
<code>sunny</code>
<highest>32.3</highest>
<lowest>28.4</lowest>
</weather>
<weather yyyymmdd="20200706">
<year>2020</year>
<month>07</month>
<date>06</date>
<comment>Plenty of sunshine</comment>
<code>sunny</code>
<highest>34.5</highest>
<lowest>30.6</lowest>
</weather>
</forecast>
In: Computer Science
Briefly describe one (1) area of green computing that Banks could implement as part of their solution to the problem/s encountered like a system glitch. [Use between 150 – 250 words]
In: Computer Science
HCS12 Assembly code please.
Translate the following code into assembly. Allocate each variable on the stack. Simulate your
program and screenshot the final value of the variables in memory.
{
char A,B,C;
int F;
A = 2;
B = 6;
C =
-
10;
F = (A + B)*C;
C = F
+10
}
In: Computer Science