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
VLD [36.1K]
3 years ago
13

(Complete the Problem-Solving discussion in Word for Programming Challenge 2 on page 404. Your Problem-Solving discussion should

include Problem Statement, Problem Analysis, Program Design, Program Code and Program Test in Words Document.) Create a program that will find and display the largest of a list of positive numbers entered by the user. The user should indicate that he/she has finished entering numbers by entering a 0.
Computers and Technology
1 answer:
zimovet [89]3 years ago
6 0

Answer:

The approach to the question and appropriate comments are given below in C++

Explanation:

Problem statement:

Write a program that will find and display the largest of a list of positive numbers entered by the user. The user should indicate that he/she has finished entering numbers by entering a 0.

Problem Analysis:

It can be completed in worst-case O(n) complexity, best case O(1) (if the first number is maxed element)

Program Design:

1. Start

2. Take the list of positive numbers for the user until he/she enter 0.

3. store the entered numbers in an array

4. find the max number from it.

5. Print the output

6. End

Program Code:

#include<iostream>

using namespace std;

int main(){

  int num = 0, *array = NULL, i= 0, counter = 0, max = 0;

 

  cout<<"Enter a list of positive numbers to find the maximum out of it and if you enter 0 that is the last number: \n";

  array = new int;

 

  /*Taking input from user until he/she enters 0*/

  while(1){

      cin>>num;

      array[i] = num;

      i++;counter++;

      if(num == 0)

          break;  

  }

 

  cout<<"Print user input numbers: \n";

  for(int i=0;i<counter;i++)

      cout<<"list["<<i<<"] --> "<<array[i]<<"\n";

  cout<<"\n";

 

  /*Find max element*/

  max = array[0];

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

      if(array[i] > max)

          max = array[i];  

  }

  cout<<"Max number = "<<max<<"\n";      

  delete array;  

  return 0;

}

You might be interested in
Assume the following JavaScript program was interpreted using staticscoping rules. What value of x is displayed in function sub1
Annette [7]

Answer:

Static scoping: x is 5

Dynamic scoping : x is 10.

Explanation:

Static scoping :

In static scoping the variable of a function take the value within the function.

If there is no values exist within the function then take the global value of the variable.

var x // No value is assigned to x so it check global value of x

function sub1() {

   document.write(“x = “ + x + “”); // So it print x = 5

}

function sub2() {

   var x;

   x = 10;

   sub1();

}

x = 5; // It is the global value of x

sub2();

Static scoping: x is 5

Dynamic scoping :

In Dynamic scoping the variable of a function take the value all the calling function ends.

If the global value is the last assigned value of a variable then it take that value.

If there exist some other function after global variable value if that function contain the variable with some assigned value variable take that value.

var x

function sub1() {

   document.write(“x = “ + x + “”);

}

x = 5; // At this point x value is 5 and check there exist a function

sub2(); // So now call this function

function sub2() {

   var x;

   x = 10; // The value of x = 5 is replaced with x = 10

   sub1();

}

Dynamic scoping : x is 10.

7 0
3 years ago
Write 3 functions in the starter code below such that: add_to_dict(): takes a dictionary, a key, a value and adds the key,value
shepuryov [24]

Answer:

Required code is given below:

Explanation:

def add_to_dict(dictt, key,value):

if key in dictt.keys():

print("Error. Key already exists.")

else:

dictt[key]=value

return dictt

def remove_from_dict(dictt,key):

try:

dictt[key]

dictt.pop(key, None)

return dictt

except KeyError:

print("No such key exists in the dictionary.")

def find_key(dictt,key):

try:

value=dictt[key]

print("Value: ", value)

except KeyError:

print("Key not found.")

4 0
2 years ago
An effective team would never have​
MA_775_DIABLO [31]

Answer:

problems or struggles

Explanation:

i believe this because with an effective team most problems aren't there and you can understand and work out problems or struggles

4 0
3 years ago
Match each definition to the correct type of media.
Murrr4er [49]

Answer:

1-2

2-3

3-1

Explanation:

I couldn't find a way to explain this.

6 0
2 years ago
Read 2 more answers
Write a method called printRangeOfNumbers that accepts a minimum, maximum numbers as parameters and prints each number from mini
timama [110]

Answer:

The method in python is as follows:

class myClass:

    def printRange(min,max):

         for i in range(min, max+1):

              print("{"+str(i)+"} ", end = '')

           

Explanation:

This line declares the class

class myClass:

This line defines the method

    def printRange(min,max):

This line iterates from min to max

         for i in range(min, max+1):

This line prints the output in its required format

              print("{"+str(i)+"} ", end = '')

5 0
3 years ago
Other questions:
  • Tom's using Google Ads to promote his bicycle store. He's created an Android App and needs to measure how effectively the curren
    14·1 answer
  • Which view In a presentation program displays you’re slides in full screen modes ?
    8·2 answers
  • A technology company only hires applicants who are under the age of 30. This company could face possibly _________ consequences
    9·2 answers
  • Letm1, m2,···mnbe distinct numbers on the number line, in the increasing order. Your goalis to color all of them blue. You have
    9·1 answer
  • The __________ vulnerability assessment is a process designed to find and document selected vulnerabilities that are likely to b
    15·1 answer
  • "The network layer is responsible for transferring packets of data from the A.Source computer to the destination computer on adj
    11·1 answer
  • Which of the following people was a member of FFA?
    7·1 answer
  • Why do people still use Intel HD graphics for gaming?
    8·1 answer
  • Can you please help me
    9·1 answer
  • • Do you think documentaries are best delivered in media such as films or documentary?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!