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
mafiozo [28]
2 years ago
10

Write an application that calculates the product of a series of integers that are passed to method product using a variable-leng

th argument list. Test your method with several calls, each with a different number of arguments.
Computers and Technology
1 answer:
Gelneren [198K]2 years ago
3 0

Answer:

The method written in C++ is as follows:

#include <iostream>

#include <stdarg.h>

using namespace std;

int prod(int listsnum,...) {

  va_list mylist;

  int product = 1;

  va_start(mylist, listsnum);

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

     product *= va_arg(mylist, int);

   

  va_end(mylist);

  return product;

}

Explanation:

This line defines the method along with the series of integers

int prod(int listsnum,...) {

This declares the variable-length list using va_list as the declaration

  va_list mylist;

This initializes product to 1

  int product = 1;

This initializes the variable-length list

  va_start(mylist, listsnum);

The following iteration calculates the product of the list

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

     product *= va_arg(mylist, int);

   

This ends the the variable-length list

  va_end(mylist);

This returns the product of the list

  return product;

}

To call the method from the main, make use of:

cout<<"Product: "<<prod(4, 2,3,4,5);

The first 4 in the list indicates the number of items in the list while the 4 other items represents the list elements

You can also make use of:

cout<<"Product: "<<prod(2, 6,5);

You might be interested in
1. How many bits would you need to address a 2M × 32 memory if:
Dominik [7]

Answer:

  1. a) 23       b) 21
  2. a) 43        b) 42
  3. a) 0          b) 0

Explanation:

<u>1) How many bits is needed to address a 2M * 32 memory </u>

2M = 2^1*2^20, while item =32 bit long word

hence ; L = 2^21 ; w = 32

a) when the memory is byte addressable

w = 8;  L = ( 2M * 32 ) / 8 =  2M * 4

hence number of bits =  log2(2M * 4)= log2 ( 2 * 2^20 * 2^2 ) = 23 bits

b) when the memory is word addressable

W = 32 ; L = ( 2M * 32 )/ 32 = 2M

hence the number of bits = log2 ( 2M ) = Log2 (2 * 2^20 ) = 21 bits

<u>2) How many bits are required to address a 4M × 16 main memory</u>

4M = 4^1*4^20 while item = 16 bit long word

hence L ( length ) = 4^21 ; w = 16

a) when the memory is byte addressable

w = 8 ; L = ( 4M * 16 ) / 8 = 4M * 2

hence number of bits = log 2 ( 4M * 2 ) = log 2 ( 4^1*4^20*2^1 ) ≈ 43 bits

b) when the memory is word addressable

w = 16 ; L = ( 4M * 16 ) / 16 = 4M

hence number of bits = log 2 ( 4M ) = log2 ( 4^1*4^20 ) ≈ 42 bits

<u>3) How many bits are required to address a 1M * 8 main memory </u>

1M = 1^1 * 1^20 ,  item = 8

L = 1^21 ; w = 8

a) when the memory is byte addressable

w = 8 ; L = ( 1 M * 8 ) / 8 = 1M

hence number of bits = log 2 ( 1M ) = log2 ( 1^1 * 1^20 ) = 0 bit

b) when memory is word addressable

w = 8 ; L = ( 1 M * 8 ) / 8 = 1M

number of bits = 0

5 0
3 years ago
You want some points? whoever answers first gets 48 points. no cap. better be quick.
LekaFEV [45]

Answer:

4

Explanation:

5 0
2 years ago
Read 2 more answers
In his work for a new company, Byron found a flower material that he could use to manufacture dresses. In his career, Byron is m
bekas [8.4K]

I guess the correct answer is plant system pathway

Thе plant systеms pathway includеs οccupatiοns rеlatеd tο grοwing fοοd, fееd, and fibеr crοps, and thе study οf plantsand thеir grοwth tο hеlp prοducеrs mееt cοnsumеr dеmand whilе cοnsеrving natural rеsοurcеs and maintaining thе еnvirοnmеnt.

In his work for a new company, Byron found a flower material that he could use to manufacture dresses. In his career, Byron is most likely focused on the plant system pathway.


5 0
3 years ago
Read 2 more answers
____ is the use of networking technology to provide medical information and services.
Cerrena [4.2K]
Answer: WebMD

WebMD, with the URL https://www.webmd.com, provides credible health and medical information on the web.
3 0
3 years ago
Which devices are managed through device management?
mr_godi [17]
Android<span>, </span>iOS<span>, Windows and </span>Blackberry<span> devices.</span>
3 0
3 years ago
Other questions:
  • What is a drawback to being in Slide Show mode? a- Being able to review each slide in order
    8·2 answers
  • Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
    14·1 answer
  • ________ hackers break into systems for non-malicious reasons such as to test system security vulnerabilities. black-hat gray-ha
    10·1 answer
  • Rest or take a break every __ minutes when typing. Please help!
    5·2 answers
  • 3. Which one of the following statements is correct? _____ variables are those whose storage bindings are created when their dec
    12·1 answer
  • What is the function of the command prompt?
    8·1 answer
  • A network that typically reaches a few meters, such as up to 10 meters (33 feet), and consists of personal devices such as mobil
    14·1 answer
  • Given a Fahrenheit value temperatureFahrenheit, write a statement that assigns temperatureCelsius with the equivalent Celsius va
    9·1 answer
  • How does a computer work
    13·1 answer
  • Richard needs to copy information from another slide presentation that uses a different design template. To ensure that the info
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!