Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of arrays as data members in C++

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "sample analysis of arrays as data members in C++". The content is simple and clear. I hope it can help you solve your doubts. Now let the editor lead you to study and learn the article "sample analysis of arrays as data members in C++".

[project-Array as data member] the following is a designed salary class (Salary):

Class Salary {public: void set_salarys (); / / enter the employee's salary (enter-1 indicates the end of wage input), the salary is saved to the salary array, and the actual number is saved to the number Void add_salarys (int x); / / give each person a salary increase of x yuan void sort_salarys (); / / A pair of wages are sorted from large to small, void show_salarys (); / / display wage information private: double salarys [50]; / / wages of multiple people int number; / / actual number}

(1) implement the member function in the Salary class, define the object of the Salary class in the main function, input the salary, give each person a salary increase of 500RMB, sort the salary data, and then output the result.

(2) enter wages manually?! It's unbearable. Now give the file salary.txt (download) containing less than 500 employees' wages, add a member function to read the data from the file, and then add a member function to save the sorted results to a file. Write main functions to test your extended functionality.

(3) organize the final program in a multi-file way.

Reference answer:

(1)

Using namespace std; class Salary {public: void set_salarys (); / / enter salary void add_salarys (int x); / / salary increase void sort_salarys (); / / sort salary void show_salarys (); / / display salary private: double salarys [50]; / / wage int number; / / actual number}; void Salary::set_salarys () {int xjingifu0; cin > > x While (x > 0) {salarys [I] = x; / salary is saved to the array data member + + I; cin > > x;} number=i; / / number is the data member, recording the number of employees} void Salary::add_salarys (int x) {int i; for (iTuno / I)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report