Programming and Graphics

(Kiana) #1

124 Introduction to C++ Programming and Graphics


#include "bsort.h"
using namespace std;

int main()
{
const int n=6;
string city[n+1];
city[1]="Oslo";
city[2]="Bayreuth";
city[3]="Chevy-Chase";
city[4]="Baltimore";
city[5]="Waco";
city[6]="Kalambaka";

string bottom = bsort<string> (n, city);

for(int i=1;i<=n;i++)
{
cout << setw(3) << right << i << " " ;
cout << setw(15) << left << city[i] << endl;
}

return 0;
}

The executablecitiesis produced by issuing the command:


c++ -o cities cities.cc

Running the executable produces on the screen the alphabetized list:


1 Baltimore
2 Bayreuth
3 Chevy-Chase
4 Kalambaka
5 Oslo
6 Waco

The main programincome.cclisted below calls this template function to
sort an array of taxpayer income in dinars:


#include <iostream>
#include <iomanip>
#include "bsort.h"
using namespace std;

int main()
{
Free download pdf