Concept explainers
you will develop a c++ program to sort the elements of a character array in descending order. Your program should ask the user to input 7 elements (of type char) for the array and sort it. For instance, if the user enters d a b e c x g, your program should display: x g e d c b a
Note: You cannot use the built-in sort function. Also, you can assume that the user only enters lower-case characters.
#include <iostream>
using namespace std;
int main()
{
char arr[7];
for(int i=0;i<7;i++){
cin>>arr[i];
}
// use bubble sort
for(int i=0;i<7;i++){
for(int j=i+1;j<7;j++){
if(arr[i]<arr[j]){
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
cout<<"Sorted array is ";
for(int i=0;i<7;i++){
cout<<arr[i]<<" ";
}
return 0;
}
Step by stepSolved in 2 steps with 2 images
- For this project the program should be made in C++ Write a menu driven program that reads an array of 10 integer from standard keyboard (user) utilizing a loop and outputs the following depending on user's choice Choice 1 - Prints the elements of array Choice 2 - Prints the minimum value of the array Choice 3 - Prints the maximum value of the array Choice 4 - Prints the product of all the numbers utilizing a loop. Choice 5 - Prints the sum of all the numbers utilizing a loop Choice 6- Print the elements of array in a reverse order When the program is done, your program should ask the user if they would like to enter another set of 10 numbers and the program should repeat itself. Input validation: Your program should only accepts integers.arrow_forwardWrite a C++ program that will read monthly sales into a dynamically allocated array. The program will input the size of the array from the user (must be less than or equal to 12). It will call a function that will find the sum of all sales. It will also call a function to find the average. It will also call a function to sort the array using either a bubble or selection sort in descending order and then display the results. You must have a comment block header at the top of your program. See the Standards document in Course Content You must use pointers for your arrays and dynamically allocate them based on the number of month You must remove and reset the array when completed You must use the correct data types for your variables You must validate your input. The number of months must be between 1 and 12 You must use a loop to read in the sales You must use at least 3 functions to calculate the average, sort the array and display the sales Your output should be…arrow_forwardyou will write a c++ program to input 5 elements (of type int) from the user and store them in an array. Your program should then reverse the array and display it. For instance, if the user enters 1 2 3 4 5 as the five elements of the array, your program should reverse it and display: 5 4 3 2 1 Note: You must use a for loop to process the array.arrow_forward
- you will develop a c++ program to find all the duplicate elements in a character array. Your program should ask the user to input 7 elements (of type char) and display all the duplicates. For instance, if the user enters d a b g a c b, your program should display: a barrow_forwardUsing C++ Program: A palindrome is a word that is spelled the same way both forwards and backwards. For example, the word, 'racecar' is a palindrome. Using character arrays, write a program that prompts the user to enter a word from the keyboard and informs the user whether the word is a palindrome or not.arrow_forwardyour goal is to modify your assignment 6 program to allow the user to pick up a random item and display a sorted list of the contents of the knap sack. note: if you use the built in c++, the most you can make on this assignment is 4 out of 10. you are expected to right your own sort based on one of the algorithms covered in class. your program should have the following: • the name of the program should be assignment 6. • 3 comment lines (description of the program, author, and date). • modify your assignment 5 program to do the following: o display a menu (use a switch statement to implement the menu) of actions ▪ attack: • for now, just display that the user chose to attack ▪ pick up item: • randomly add one of 6 items to an array named knapsack o you get to choose the item names • display which item the user picked up ▪ add an option to the main switch statement: display knap sack contents • the contents of the knap sack must be sorted The knapsack items are bananas, lays,…arrow_forward
- This is warning you, don't use any AI platform to generate answer.arrow_forwardWrite a C++ program that helps the user plan out their budget. It should ask the user for the most recent 5 things that they bought; it should ask for both the name for the item and its price. Then, print out the following: total money spent, average money spent per item, lowest priced item, and highest priced item. You can assume that each item has a different name and a different price. You must use at least 1 array and you must display all numbers as dollar values (exactly 2 places after the decimal) EXPECTED OUTPUT Welcome to the Budget Helper. What are the last 5 things you bought? Item 1 name: Bananas Item 1 price: 1.5 Item 2 name: Shoes Item 2 price: 45 Item 3 name: Coffee Item 3 price: 2.5 Item 4 name: Metrocard Item 4 price: 120 Item 5 name: Jacket Item 5 price: 89 The total amount you spent is $258The average price per item is $51.60The cheapest item is BananasThe most expensive item is Jacketarrow_forwardC++ In this lab, you're going to be working with partially filled arrays that are parallel with each other. That means that the row index in multiple arrays identifies different pieces of data for the same person. This is a simple payroll system that just calculates gross pay given a set of employees, hours worked for the week and hourly rate. Parallel Arrays First, you have to define several arrays in your main program: employee names for each employee hourly pay rate for each employee total hours worked for each employee gross pay for each employee You can use a global SIZE of 50 to initialize these arrays. Second, you will need a two dimension (2-D) array to record the hours worked each day for an employee. The number of rows for the 2-D array should be the same as the arrays above since each row corresponds to an employee. The number of columns represents days of the week (7 last I looked). Functions Needed In this lab, you must read in the employee names first because this…arrow_forward
- help with c++...paste indented code plzz Q3: Ask user enter size of array N, then ask user enter maximum number of array element X, then create an array size N, and assign each element of array to random number between 1~X. Print the array, and also find which element appeared most in the array, print all if there are multiple elements which are most at the same time. Sample input: Enter N: 20 Enter X: 10 Sample output: 8 7 10 8 1 7 4 3 4 7 5 6 4 3 1 10 1 9 9 10 1 4 7 appear mostarrow_forwardwrite a c++ program that declares an array that can hold 20 chars. then the program outputs two upper case character which are A & Z(initials). next using a loop the program populates the array with the pair of the initials until the array is full. then the program outputs the array on one line. then the program swaps the contents of the first and last locations in the array and output the modified array on the next line.arrow_forwardYou are given a binary array containing only 0's and 1's. You have to sort the array and you can swap any elements in the array. Write a C++ program to find the minimum number of swaps required to sort the array. Input the array and its size from the user and display the minimum number of swaps in the output.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education