
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
I need some help coding this in c++. Please and thank you

Transcribed Image Text:unction
10:28
all 32%
Example 6
Sort the following array in
an ascending order. int
array {32, 23, 43, 21, 39,
31, 15, 34, 38, 14}. Use
the algorithm given on the
last slide.
1 / Example
// Sort array in ascending order
tinclude ciostrean
4 laclude cstring
using nanespace std,
int main()
int a[10)-(32, 23, 43, 21, 39, 31, 15, 34, 38, 14);
Int tene; //for spping
10
for(int i-e; ic1e; i
11-
12
for(int 1-1+1; k10:1++)(//compare with next elenent onards
teno-al1):
/SAP process starts
(/store fiest elesest
14
15
I/store the second element into first
(/store the temp (has first) Into second
I/Elements are sapped
als)-temp
18
19
20
21
22
23 )
I/print serted array
for(int ie; i1e; i)
coute ca[1k :
12
Example 7
• Rewrite example 6 and make the sorting code as a function
fSortAsc(array, length). This function will also print the
sorted array. Call this function in main (). Use the same array
as in example 6. Here is a portion of what the main () looks
like for this example. Hint: move the sort code from example 6
to the function fSortAsc.
I/ MB Example 7
I/ Sort array function
include clostream
tinclude string
susing namespace std;
vodd fSortasc(int al), int length),
int mainO
int a[10)-(32, 23, 43, 21, 39, 31, 15, 34, 18, 14);
fSortáscia, 1a);
10
11
13
12 }
13
Example 8
• Continue example 7 and add the sorting of the array in
descending order as a function fSortDesc(array,length).
This function will also print the sorted array. Call this function
in main. Use the same array as in example 6. The main() must
look like this.
I H Ecample a
/ Sort array function
3 tinelude ciestream
4 Binclude cstring
using nanespace std;
veld fSortasc(int all, Int length);
7 void fSortDesc(int all, int length);
9 int nain()
19-
int a[101-(32, 23, 43, 21, 39, 31, 15, 34, 38, 14);
12 Sortáscia, 10)
ceutccendl;
14 Sortbesc(a,10):
15 }
11
14
14
Matrices- two dimensional arrays
A matrix is a table with rows and columns
![10:28 A
令.all 32%
M8- Arrays 2 - Read-only
cample 6
1 / M8- Example 6
// Sort array in ascending order
2
3.
#include <iostream>
#include <string>
5 using namespace std;
4
int main()
int a[10]={32, 23, 43, 21, 39, 31, 15, 34, 38, 14};
int temp; //for swapping
for(int i=0; i<1®; i++){
for (int j-1+1; j<1@;j++){//compare with next element onwards
10
11.
12-
if(a[i]>a[j]){
temp-a[i];
a[i]-a[j];
a[j]-temp;
13-
14
//SWAP process starts
//store first element
//store the second element into first
//store the temp (has first) into second
//Elements are swapped
15
16
17
18
19
20
//print sorted array
for(int i=0; i<l®; i++)
cout<ca[1]<<" ";
21
22
23 }
12
cample 7
ke the sorting code as a function
. This function will also print the
ion in main (). Use the same array
portion of what the main () looks
move the sort code from evamnle 6.](https://content.bartleby.com/qna-images/question/83f8fd0e-20e0-4045-b7e0-eac2c26a0bae/9f76b72b-5159-463d-9864-f3c169efc456/5kgqgmr_thumbnail.jpeg)
Transcribed Image Text:10:28 A
令.all 32%
M8- Arrays 2 - Read-only
cample 6
1 / M8- Example 6
// Sort array in ascending order
2
3.
#include <iostream>
#include <string>
5 using namespace std;
4
int main()
int a[10]={32, 23, 43, 21, 39, 31, 15, 34, 38, 14};
int temp; //for swapping
for(int i=0; i<1®; i++){
for (int j-1+1; j<1@;j++){//compare with next element onwards
10
11.
12-
if(a[i]>a[j]){
temp-a[i];
a[i]-a[j];
a[j]-temp;
13-
14
//SWAP process starts
//store first element
//store the second element into first
//store the temp (has first) into second
//Elements are swapped
15
16
17
18
19
20
//print sorted array
for(int i=0; i<l®; i++)
cout<ca[1]<<" ";
21
22
23 }
12
cample 7
ke the sorting code as a function
. This function will also print the
ion in main (). Use the same array
portion of what the main () looks
move the sort code from evamnle 6.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 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-science and related others by exploring similar questions and additional content below.Similar questions
- Please us c++ to make the code thank you very much!arrow_forward. In what way is the calling convention used by the Irvine32 library not compatible with thecalling convention used by the C and C++ languages?arrow_forwardI need help making this program in C programming. Please look at the pictures provided at that helps. Thank You!arrow_forward
- List two features we used from the C++ standard library, including a short explanation of why you would use the feature and which header file must be included. Example: The std::cin object is found in the iostream header file and is used to read characters from the keyboard.arrow_forwardMake C++ program.Your travel agency offers trips to Asian and African countries. This month, you are specifically doing trips to the Philippines (in Asia) and Tunisia (in Africa) and created a program for users to get prices and a boarding ticket. For all Asian countries, you store the name and population information in your program. With African countries, in addition to the name and population, you are also interested in location (North, South, East, West). Create an abstract Country class that holds the country name and population (given by the constructor). There should be two functions: int get_ticket_price and void_print_boarding_pass (which will output a boarding pass as a file-see below) Using the Country class, create two classes called African_country and Asian_country. The Asian_country class should use the same constructor that the Country class uses and the African_country class constructor should allow for the user to enter the location (see sample run).…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- 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

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education