1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Kaylis [27]
3 years ago
11

Write a program for a grocery store to calculate the total charge for customers. In the main: Your program should ask customer t

he number of items that he/she is purchasing and it should check to see it is less than or equal to 20 items , then your program should pass than number to FillPriceArray subroutine and call FillPriceArray subroutine.
Computers and Technology
1 answer:
gavmur [86]3 years ago
8 0

Answer:

Hello Joelwestwood! This is a good question to check your knowledge of subrountines and Arrays. Please find the implementation with the explanation below.

Explanation:

The solution can be implemented in a number of languages including C++, Java and Python to name a few. Though the implementation language is not specified in the question, i'll provide you the implementation code in Python and also in Java. Java implementation is a little complex because we need to define an array size to be able to add items to it, whereas Python allows us more flexibility by allowing dynamic size of Array.

JAVA IMPLEMENTATION

import java.util.Scanner;

import java.util.Arrays;

class TotalCharge {

 private static int[] price_array = new int[1];

 public void FillPriceArray(int price) {

   if (price_array.length == 1) {

     price_array[0] = price;

   } else {

     price_array = new int[price_array.length + 1];

     price_array[price_array.length + 1] = price;

   }

 }

 public int[] get_price_array() {

   return price_array;

 }

 public static void main(String args[]) {

   System.out.println("Please enter the total number of items to purchase: ");

   Scanner scan = new Scanner(System.in);

   int price = scan.nextInt();

   if (price <= 20) {

     System.out.println("Items being purchased are less than 20");

   } else {

     System.out.println("Items being purchased are more than 20");

   }

   TotalCharge itemsTotal = new TotalCharge();

   itemsTotal.FillPriceArray(price);

   System.out.println(Arrays.toString(itemsTotal.get_price_array()));

 }

}

PYTHON IMPLEMENTATION

calculate_total_charge.py

def FillPriceArray(price):

 price_array.append(price)

price_array = []

price = raw_input("Please enter the total number of items to purchase: ")

try:

 price = int(price)

 if price <= 20:

   print("Items being purchased are less than 20")

 else:

   print("Items being purchased are more than 20")

 FillPriceArray(price)

 print(price_array)

except ValueError:

 print("Invalid input! Exiting..")

You might be interested in
Technology never has negative consequences for society. true or false.
never [62]
False, as an example, new technology that is not yet perfected can cause huge problems and even old technology can still cause problems. Technology doesn't always solve things a lot of the time it just changes the problem
3 0
3 years ago
Vector images take up much less space when saved to a computer or storage device because computers and storage devices just need
AleksandrR [38]

Answer:

False

Explanation:

4 0
2 years ago
Read 2 more answers
Under normal operations, cisco recommends that you configure switch ports on which vlan
larisa86 [58]

 

You can configure switch ports on default VLAN under normal operations. Cisco switches always have VLAN 1 as the default VLAN, which is required for many decorum communications between switches like spanning-tree protocol for example. It is obligatory not to delete or even change the default VLAN.

 

 





3 0
3 years ago
Do opportunity costs only occur when making spending decisions
Naily [24]

Answer:

yes there is opportunity in every thing such as do i buy this car what am i going to miss out on if i buy this what does this offer

Explanation:

6 0
3 years ago
1.1. (30 points) Write a program to calculate the average number of cars sold by a car agency over a period of years for the fir
mario62 [17]

Answer:

count = 0

months = 0

years = int(input("Enter the number of years: "))

for year in range(1, years+1):

   cars_sold = int(input("Enter the number of cars sold in first six months: "))

   count += cars_sold

   months += 6

print("Number of months: " + str(months))

print("Number of cars sold in total: " + str(count))

print("Average number of cars sold per month: " + str(count / months))

Explanation:

Initialize the variables

Ask the user for the number of years

Create a for loop that iterates depending on the given number of years

Ask the user for the number of cars sold in the first six months of the year

Increment the count by given number and increment the months by 6 after each iteration

Print the months, count and, average

8 0
3 years ago
Other questions:
  • The ret instruction (without operands) will pop how many bytes off the stack?
    7·1 answer
  • Which of the following statement is most accurate? A. A reference variable is an object. B. A reference variable refers to an ob
    6·1 answer
  • Which of the following statements about computer graphics formats is true?
    14·1 answer
  • If a firm's pages are not near the top of query results, customers may never discover its website. This has led to _____ becomin
    12·1 answer
  • Who designed analatic engine in the 1930's?​
    10·1 answer
  • What is the 5 basic steps of computer programing?
    6·1 answer
  • ICD-10-CM diagnosis codes are entered in Block 21 of the CMS-1500 claim. A maximum of __________ ICD-10- CM codes may be entered
    14·1 answer
  • Hello im looking for someone to answer my question. Its about a coding project called "Quiz Master". Im having trouble with the
    7·1 answer
  • ____coping skills are instinctive.<br> A. All<br> B. No<br> C. Some
    9·1 answer
  • I’ll give brainliest if answers are correct
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!