Project 5-array as data member

Source: Internet
Author: User

[Cpp]/** Copyright (c) 2013, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Fan Lulu * Completion Date: July 15, March 23, 2013 * version: v1.0 ** input Description: none * Problem description: * program output: * Problem Analysis: * Algorithm Design: omitted */header file: [cpp] class Salary {public: void getSalary (); // enter the salary and save the Salary to the salary array, the actual number of people is saved to number void raiseSalary (int x); // raise salary void sortSalary (); // sort the salary void outputSalary (); // output salary private: double salary [50]; int number;}; class definition file: [cpp] # include "Salary. h "# include <iostream> using namespace std; void Salary: getSalary () {int I; cout <" Enter the number of workers "<endl; cin> number; cout <"Enter the salary" <endl; for (I = 0; I <number; I ++) cin> Salary [I];} void salary :: raiseSalary (int x) {int I; for (I = 0; I <number; I ++) salary [I] + = x;} void Salary: sortSalary () {int I, j; double t; for (I = 0; I <number-1; I ++) for (j = 0; j <number-i-1; j ++) if (salary [j] <salary [j + 1]) {t = salary [j]; salary [j] = salary [j + 1]; salary [j + 1] = t ;}} void Salary: outputSalary () {int I; for (I = 0; I <number; I ++) cout <salary [I] <";} Main file: [cpp] # include" Salary. h "# include <iostream> using namespace std; int main () {Salary s; int money; s. getSalary (); cout <"Enter the salary increase:"; cin> money; s. raiseSalary (money); cout <"after salary increase" <endl; s. outputSalary (); cout <endl; s. sortSalary (); cout <"after wage sorting" <endl; s. outputSalary (); cout <endl; system ("PAUSE"); return 0;} running result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.