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
zmey [24]
2 years ago
14

Write a program called array1.cpp file that use either regular for loop or range based for loop to display the contents of the a

rray test []. You can also write a function to display the contents of array. Submit your code array1.cpp to Blackboard.
Computers and Technology
1 answer:
ch4aika [34]2 years ago
7 0

Answer:

The program in C++ is as follows:

#include <iostream>

using namespace std;

void display(int array_test [], int n){

   for(int i = 0; i<n;i++){

       cout<<array_test[i]<<" ";   }

}

int main(){

   int n;

   cin>>n;

   int array_test[n];

   for(int i = 0; i<n;i++){

       cin>>array_test[i];

   }

   display(array_test,n);

   return 0;

}

Explanation:

This defines the display function

void display(int array_test [], int n){

This iterates through the array

   for(int i = 0; i<n;i++){

This prints each element of the array

       cout<<array_test[i]<<" ";   }

}

The main begins here

int main(){

This declares n as integer; n represents the length of the array

   int n;

This gets input for n

   cin>>n;

This declares the array

   int array_test[n];

The following iteration gets input for the array

   for(int i = 0; i<n;i++){

       cin>>array_test[i];

   }

This calls the display function to display the elements of the array

   display(array_test,n);

   return 0;

}

You might be interested in
Write a function maxTemp which takes a filename as string argument and returns the maximum temperature as float type for the wee
Alenkinab [10]

Answer:

#section 1

def maxTemp(filename):

   import pathlib

   f = pathlib.Path(filename)

   f.exists()

   if f.exists():

       f = open(filename, "r")

#section 2

       next(f)

       res = [int(sub.split(',')[1]) for sub in f]

       maxdata = (res[0])

       for i in range(len(res)-1):

           if maxdata < res[i]:

               maxdata = res[i]

       

       index = res.index(maxdata)

       f.close()

 #section 3  

       li = []  

       a = open(filename, "r")

       for line in a:

           line = line.strip()

           li.append(line)

   

       

       a.close()

       return (li[index+1])

   else:

       return -1

print(maxTemp("new.csv"))

Explanation:

#section 1:

The function maxTemp is defined. We import pathlib in other to check if the file exists, if it does we carry on with opening the file and if it doesn't the program returns -1.

#section 2:

We start splitting the sub-lists from the second line i.e <em>next(f)</em>. For each line we take the second index element and convert it to an integer.

<em>res = [int(sub.split(',')[1]) for sub in f] </em>

The maximum number is gotten by using the if statement to compare all elements in the list.  The index of the maximum item in the list is collected.

the file is then closed.

#section 3  :

The file is re-opened and all the lines are striped and passed into a new list and the index recovered from section 2, is used to get the day with the highest temperature and the line is returned.

8 0
3 years ago
In which step of writing a program does a programmer first use a<br> compiler?<br> documentin
Allisa [31]

A compiler is often used when you want to test your code; that would often be your second step.

6 0
2 years ago
"Different links can transmit data at different rates, with the _______ of a link measured in bits/second"
murzikaleks [220]

Answer: Transmission rate

Explanation:

 Transmission rate is measured in bits per second and it transmitted the data at the different rate across the circuit. The speed in which the data rate is transferred from one device to anther is known as transmission rate.

The transmission rate are always less as compared to signalling rate because the signalling rate contain the total data which basically include the overhead to control the information.

Therefore, transmission rate is the correct option.

 

7 0
3 years ago
What is heaven backwards?
sweet-ann [11.9K]
It is Nevaeh backwards hope that helps! :3 and feel free to pm me if you have anymore questions! :3
5 0
2 years ago
Read 2 more answers
A small grocery store has one checkout.You have been asked to write a program to simulate the grocery store as it checks out cus
Masteriza [31]

Answer:

Check the explanation

Explanation:

PYTHON CODE :

#import random function

from random import randint

#class Queue declaration

class Queue:

#declare methods in the Queue

def __init__(self):

self. items = []

def isEmpty(self):

return self. items == []

def enqueue(self, item):

self.items. insert(0, item)

def dequeue(self):

return self. items. pop()

def size(self):

return len(self. items)

def getInnerList(self):

return self.items

#This is customer Queue

class Customer:

#declare methods

def __init__(self,n):

self.numberOfItems=n

def __str__(self):

return str(self. numberOfItems)

def getNumberOfItems(self):

return self. numberOfItems

#This is expresscheker customer queue

class Expresschecker:

def __init__(self,n):

self.numberOfItems=n

def __str__(self):

return str(self. numberOfItems)

def getNumberOfItems(self):

return self. numberOfItems

#Returns random checkout time, based on number of items

def checkOut(Expresschecker):

items = Expresschecker. getNumberOfItems()

if items <= 10:

return randint(2, 5)

if items <= 20:

return randint(6, 9)

return randint(10, 14)

#Initiate queue for the Expresschecker

Expresschecker = Queue()

#declare total customers

totalcheckoutCustomers = 10

#express Customers shopping..

for i in range(totalcheckoutCustomers):

#Each putting Between 1 to 25 items

randomItemsQty = randint(1, 25)

customer = Customer(randomItemsQty)

#Getting into queue for checkout

Expresschecker. enqueue(customer)

#====Now all express Customers having

#random qty of items are in Queue======

#intial time

totalTime=0

#define the size of the queue

totalcheckoutCustomers = Expresschecker. size()

#using for-loop until queue is empty check out

#the items in the express cheker queue

while not(Expresschecker. isEmpty()):

totalTime+=randint(1,5)

#Picking a customer

expresscustomer = Expresschecker. dequeue()

#Processing the customer

timeTaken = checkOut(expresscustomer)

#add the time for each custimer

totalTime+=timeTaken

#compute average waiting time

averageWaitingTime = totalTime/totalcheckoutCustomers

#display the average waiting time

print("Average waiting time for the express customer queue is "

+str(averageWaitingTime)+" minutes ")

print("Remaining Custimers in the express customer Queue is: ",

Expresschecker. size())

#Returns random checkout time, based on number of items

def checkOut(customer):

items = customer. getNumberOfItems()

if items <= 10:

return randint(1, 5)

if items <= 20:

return randint(6, 10)

return randint(11, 15)

#in

customersQueue = Queue()

totalCustomers = 20 #Change number of customers here

#Customers shopping..

for i in range(totalCustomers):

#Each putting Between 1 to 25 items

randomItemsQty = randint(1, 25)

customer = Customer(randomItemsQty)

#Getting into queue for checkout

customersQueue. enqueue(customer)

#====Now all Customers having random qty

#of items are in Queue======

totalTime=0

totalCustomers = customersQueue. size()

while not(customersQueue. isEmpty()):

totalTime+=randint(1,5)

#Picking a customer

customer = customersQueue. dequeue()

#Processing the customer

timeTaken = checkOut(customer)

totalTime+=timeTaken

#Result=============================

averageWaitTime = totalTime/totalCustomers

print("Average wait time for the customer queue is

"+str(averageWaitTime)+" minutes ")

print("Remaining Customers in the customer Queue is:

",customersQueue. size())

5 0
3 years ago
Other questions:
  • You would like to arrange the records alphabetically. You should _____.
    7·2 answers
  • A cybersecurity analyst is currently investigating a server outage. The analyst has discovered the following value was entered f
    9·1 answer
  • What part of the network is the point where the responsibility of the administrator ends and the telecommunications providers re
    5·1 answer
  • Determine if the following statement is true or false:
    5·2 answers
  • If an author is creating a reference list and wants the second and succeeding lines indented for a reference, they should select
    13·2 answers
  • The marketplace for computer hardware:________ 1. has become increasingly concentrated in top firms 2. has expanded to include a
    5·2 answers
  • Question 8 A data analyst is working with a data frame named stores. It has separate columns for city (city) and state (state).
    12·1 answer
  • Answer all of the questions,
    7·1 answer
  • The original programs awaiting tanslation is called​
    11·1 answer
  • Select the WRONG statement about Slide Transitions.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!