# 毕业 设计题。 大佬 帮忙的重重有赏。 急用 ，谢谢各位大佬了

0

FirstNameI LastNamel assistant
60055.95
FirstName2 LastName2 associate
81112.45

FirstName1000 LastName1000 full
92255.21

0

0

Ծ‸Ծ

0

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;

namespace cnblog_132765
{
class Program
{
readonly static SalaryBand assistant = new() { Name = "assistant", Floor = 50000, Upper = 80000 };
readonly static SalaryBand associate = new() { Name = "associate", Floor = 60000, Upper = 110000 };
readonly static SalaryBand full = new() { Name = "full", Floor = 75000, Upper = 130000 };
readonly static SalaryBand[] salaryBands = new SalaryBand[3] { assistant, associate, full };
static void Main(string[] args)
{
var file = CreateData();

using var fileStream = new FileStream(file, FileMode.Open);
List<Teacher> teachers = new();
var line = string.Empty;
var lineSalary = string.Empty;
string[] t = new string[3];
{
t = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
// 统计
var group = teachers.GroupBy(t => t.Type).Select(g => new
{
// 总额
Total = Math.Round(g.Sum(s => s.Salary), 2, MidpointRounding.ToEven),
Avg = Math.Round(g.Average(s => s.Salary), 2, MidpointRounding.ToEven),
Count = g.Count()
}).OrderBy(g => g.Total).ToList();
Console.WriteLine("职称      \t总金额    \t平均工资  \t总人数");
foreach (var g in group)
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}", g.JobTitle, g.Total, g.Avg, g.Count);
}
}
static string CreateData()
{
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var fileName = Path.Combine(path, Guid.NewGuid().ToString("N") + ".txt");
using var file = new FileStream(Path.Combine(path, fileName), FileMode.OpenOrCreate);
var sb = new StringBuilder();
int cnt = 1000;
Random random = new Random();
for (int i = 1; i <= cnt; i++)
{
var randomBands = salaryBands[random.Next(0, 3)];
sb.AppendLine(\$"FirstName{i} LastName{i} {randomBands.Name}");
sb.AppendLine(\$"{random.Next(randomBands.Floor, randomBands.Upper) + Math.Round(random.NextDouble(), 2)}");
}
var buffer = Encoding.Default.GetBytes(sb.ToString());
file.Write(buffer, 0, buffer.Length);
return fileName;
}
}

struct SalaryBand
{
public string Name;
public int Floor;
public int Upper;
}

public record Teacher
{
public string FirstName { get; }

public Teacher(string firstName, string type, double salary)
{
FirstName = firstName;
Type = type;
Salary = salary;
}

public string Type { get; }
public double Salary { get; }
}
}
Jonny-Xhl | 园豆：664 (小虾三级) | 2020-12-20 20:49
0

0

0

ycyzharry | 园豆：23575 (高人七级) | 2020-12-22 00:18
0

您需要登录以后才能回答，未注册用户请先注册