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 using namespace std; // Function Name int sumAll(int num[5]); void display(int num[5]); //Variable global declaration int x, sum=0, choice;
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 using namespace std; // Function Name int sumAll(int num[5]); void display(int num[5]); //Variable global declaration int x, sum=0, choice;
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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";
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
{
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] << " "; }
}
{ cout<<num[x] << " "; }
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 4 images
Knowledge Booster
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.Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY