Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
Direction: Complete the program below using case switch statement and single array with Function. Copy
the source code and screen the sample output.
PROGRAMMING
//Single array - A group of consecutive memory locations of the same name and type, structures of related
data items.
//Array index always starts with zero.
// Single array with function
#include<iostream>
using namespace std;
// Function Name
int sumAll(int num[5]);
void display(int num[5]);
//Variable global declaration
int x, sum=0, choice;
int num[5];
main(){
// Save the input numbers to the memory
for(x=0; x<=4; x++)
{ cout<<(" Enter a number: ");
cin>>num[x];
}
cout<<"\nCHOICES: ";
cout<<"\n 1.The sum of all numbers ";
cout<<"\n 2. The sum of even subscripts";
cout<<"\n 3. The sum of even numbers ";
cout<<"\n 4. The product of odd subscripts ";
cout<<"\n 5. The product of odd numbers ";
cout<<"\n 6. The highest number ";
cout<<"\n 7. The lowest number ";
cout<<"\n 8. Display all numbers";
 
 
 
 
 
 
 
do{
cout<<("\n\nEnter your choice[1-7]: ");
cin>>choice;
switch(choice)
{ case 1:cout<< "Display the sum of all numbers";
sum= sumAll(num);
cout<<"\nThe sum is "<<sum;
break;
case 2:cout<< "Display the sum of numbers in even subscripts";
sum=0;
for(x=0; x<=4; x=x+2)
{ sum = sum +num[x]; }
cout<<"\nThe sum is "<<sum;
break;
case 3:cout<< "Display the sum of even numbers";
sum=0;
for(x=0; x<=4; x++)
{if (num[x] % 2==0)
{
sum = sum +num[x];
} // if
} //for loop
cout<<"\nThe sum is "<<sum;
break;
case 8: cout<< "\nDisplay all numbers\n";
display(num);
break;
default : cout<<"\nYou entered an Invalid Number\n\n";
} //switch
} while (choice<=8);
} // end of main
//START OF FUNCTION
int sumAll(int num[5]) //case 1 Sum all numbers
{ sum=0;
for(x=0; x<=4; x++)
{ sum = sum +num[x]; }
return sum; }
void display(int num[5]) // case 8 display all numbers
{
 
 
 
 
 
 
 
for(x=0; x<=4; x++)
{ cout<<num[x] << " "; }
}
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY