/* Copyright (c) 2014, Yantai University School of Computer * All rights reserved. * File name: Test.cpp *: Liu Chang * completion date: 2014 monthly * Version number: v1.0 * * Problem Description: Design a program, enter three integers, order it from large to small output, require (1) sorting function With the function implementation, three integers with three variables, do not have to define the array, (2) write two versions of the function, one takes the address value of the method, and the other takes the reference type as parameters. * Input Description: Three integers, * program output: This three integers from large to small output.
#include <iostream>using namespace std;void Exchange (int &q1,int &q2,int &q3), void swap (int &p1, int &p2); int main () { int a,b,c; cin>>a>>b>>c; Exchange (A,B,C); cout<<a<< "<<b<<" "<<C;} void Exchange (int &q1,int &q2,int &q3) { if (Q1<Q2) swap (Q1,Q2); if (Q1<Q3) swap (Q1,Q3); if (Q2<Q3) swap (Q2,Q3);} void swap (int &p1,int &p2) { int temp; TEMP=P1; P1=P2; P2=temp;}
Operation Result:
Learning experience:
Well, originally was ready to ask the teacher how to use, but did not think of a book on the books there are examples Ah, according to the reference type as an example of parameters or completed the project, it seems to be too dependent on the teacher, I was wrong.
17th Week Project 2--Reference as a row parameter (three-digit ordering (reference type as parameter))