Question

In: Computer Science

c++ language for this assignment use real world example. Your application must be a unique project...

c++ language

for this assignment use real world example.

Your application must be a unique project and must incorporate the use of an STL container and/or iterator and at least 7 STL algorithms with an option to exit. Your application must contain at least 8 menu options. You will decide how to implement these menu selections.

Solutions

Expert Solution

ANSWER :-

GIVEN THAT :-

// to demonstrate use of STL algorithms
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric> //For accumulate operation

using namespace std;

// 1. funtion to sort array
void sort_array(){
int arr[5];
cout << "Enter 5 elements of the array: " ;
// input the array
for(int i = 0; i < 5; i++){
cin >> arr[i];
}
// sort the array with STL sort function
// sorting to enable use of unique()
sort(arr, arr+5);

// print sorted array
cout << "Sorted array: ";
for(int i = 0; i < 5; i++){
cout << arr[i] << " ";
}
}
  
  
// 2. funtion to reverse array
void rev_array(){
int arr[5];
cout << "Enter 5 elements of the array: " ;
// input the array
for(int i = 0; i < 5; i++){
cin >> arr[i];
}
// reverse the array with STL reverse function
reverse(arr, arr+5);

// print reversed array
cout << "Reversed array: ";
for(int i = 0; i < 5; i++){
cout << arr[i] << " ";
}
}

// 3. funtion to find min of array
void min_array(){
int arr[5];
cout << "Enter 5 elements of the array: " ;
// input the array
for(int i = 0; i < 5; i++){
cin >> arr[i];
}
//min of array
int ele = *min_element(arr, arr+5);

// print min element in array
cout << "Min element in array: " << ele << endl;
}

// 4. funtion to find max of array
void max_array(){
int arr[5];
cout << "Enter 5 elements of the array: " ;
// input the array
for(int i = 0; i < 5; i++){
cin >> arr[i];
}

//max of array
int ele = *max_element(arr, arr+5);

// print max element array
cout << "Max element in array: " << ele << endl;
}


// 5. funtion to search for an element in the array
void search_array(){
int arr[5];
cout << "Enter 5 elements of the array: " ;
// input the array
for(int i = 0; i < 5; i++){
cin >> arr[i];
}
int ele;
cout << "Enter element to search: ";
cin >> ele;

//search the array
find(arr, arr+5,5) != arr+5? cout << "\nElement found": cout << "\nElement not found";
}

// 6. funtion to sum the array
void sum_array(){
int arr[5];
cout << "Enter 5 elements of the array: " ;
// input the array
for(int i = 0; i < 5; i++){
cin >> arr[i];
}
// sum the array
cout << accumulate(arr, arr+5, 0);
  
}


// 7. funtion to count occurences of an element in the array
void count_array(){
int arr[5];
cout << "Enter 5 elements of the array: " ;
// input the array
for(int i = 0; i < 5; i++){
cin >> arr[i];
}
int ele;
cout << "Enter element to be counted: ";
cin >> ele;

// count the array
cout << count(arr, arr+5, ele);
}

// 8. funtion to eliminate duplicate of the array
void remove_dup_array(){
vector<int> vect;
cout << "Enter 5 elements of the array: " ;
int temp;
// input the array
for(int i = 0; i < 5; i++){
cin >> temp;
vect.push_back(temp);
}
// sum the array
// Deletes the duplicate occurrences
vect.erase(unique(vect.begin(),vect.end()),vect.end());

cout << "Array after eliminating duplicates: " << endl;
for(auto e: vect){
cout << e << " ";
}
}

// Driver code
int main()
{
while(1){

// Menu
cout << "\nMENU" << endl;
cout << "1. Sort an array: " << endl;
cout << "2. Reverse an array: " << endl;
cout << "3. Find Minimum element of an array: " << endl;
cout << "4. Find Maximum element of an array: " << endl;
cout << "5. To search an element in an array: " << endl;
cout << "6. To find sum of an array: " << endl;
cout << "7. To count occurences of an element in an array: " << endl;
cout << "8. Eliminate duplicates of an array: " << endl;
cout << "9. Exit: " << endl;
  
// input the option
int option;
cin >> option;
  
// lets create a switch case to navigate in the menu
switch(option){
case 1:
sort_array();
break;
case 2:
rev_array();
break;

case 3:
min_array();
break;
case 4:
max_array();
break;
case 5:
search_array();
break;
case 6:
sum_array();
break;
case 7:
count_array();
break;
case 8:
remove_dup_array();
break;
case 9:
return 0;
}
}
  
}

OUTPUT :-


Related Solutions

Describe any real world engineering application your project represents. Describe similarities and differences between your project and the real world scenario.
Arduino ProjectDescribe any real world engineering application your project represents. Describe similarities and differences between your project and the real world scenario.Write algorithm and flow chart for the program.Required equipment.Objective is too great program design with algorithm and flowchart for annany day engineering application.
Search on the internet to find some real world example of the application of flexible budgets...
Search on the internet to find some real world example of the application of flexible budgets or standard costs
C Mini Project is a mini application that could be developed using C language that involves...
C Mini Project is a mini application that could be developed using C language that involves the concepts of arrays, functions, read and write data techniques. Based on your creativity, you are required to plan, design and develop a mini application for an organisation. You may choose to from the list below or propose your own mini application: 1. Customer Billing System 2. Employee Record System 3. Contact Management System 4. Appointment Management System 5. Attendance Record System Your responsibility...
Explain a real world application of Engineering Economics. It must be more than 300 words and...
Explain a real world application of Engineering Economics. It must be more than 300 words and less than 600 words. Show a real world example!
Assignment (C language, not C ++) Start a new project to store grade information for 5...
Assignment (C language, not C ++) Start a new project to store grade information for 5 students using structures. Declare a structure called student_t that contains : First name Last name Student ID Number Percentage grade Letter grade Create the following functions: getStudentInfo(void)- Declares a single student object - Uses printf()/scanf() to get keyboard input for Name, SID, and Percentage (not Letter). - Returns a single student structure calcStudentGrade(student_t *st_ptr)- Takes the pointer to a student (to avoid making a...
Use a personal example or a text example or a business problem from the real world...
Use a personal example or a text example or a business problem from the real world to illustrate one or more of the Decision Analysis models covered. Why was the particular model chosen? Which model(s) might provide a better decision for this problem? Assign probabilities to the problem (if not already assigned) and determine the Expected Value solution. *Please use different answers from the chegg since my friends already using it. Thankyou.
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
Use an example from the real world that illustrates the effective, or ineffective, use of decision...
Use an example from the real world that illustrates the effective, or ineffective, use of decision making using the steps listed. Discuss why they were successful or not successful. Be specific about which steps were missed, not used, ineffective, etc.
This week, your assignment is to go out into the real world and find a product...
This week, your assignment is to go out into the real world and find a product or service of your choosing, then using the components of the 4E framework listed above, outline how an entrepreneur marketing this product or service can augment or enhance his or her marketing mix efforts via social media.
1. What makes the binomial distribution unique? What are its characteristics? Give a real-world example of...
1. What makes the binomial distribution unique? What are its characteristics? Give a real-world example of a distribution of data that would be considered binomial. 2. Solve the following problem: About 30% of adults in United States have college degree. (probability that a person has college degree is p = 0.30). If N adults are randomly selected, find probabilities that 1) exactly X out of selected N adults have college degree 2) less than X out of selected N adults...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT