In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.