当前位置:网站首页>C set
C set
2022-04-23 03:22:00 【C # primary advanced】

aggregate (Collection) Class is a class designed for data storage and Retrieval . These classes provide a pair of stacks (stack)、 queue (queue)、 list (list) Hash table (hash table) Support for . Most collection classes implement the same interface .
aggregate (Collection) Classes serve different purposes , Such as dynamically allocating memory for elements , Index based access to list items, etc . These classes create Object A collection of objects of a class . stay C# in ,Object Class is the base class for all data types .
- There is a known Worker Under the class :
public class Worker
{
private int age;
private string name;
private double salary;
public Worker ()
{
}
public Worker (String name, int age, double salary)
{
this.name = name;
this.age = age;
this.salary = salary;
}
public void work(){
Console.WriteLine(" full name :" + name + " Age :" + age + " Wages :" + salary + " work");
}
}
Complete the following requirements
- Create a List, stay List Add three workers to the , The basic information is as follows :
full name Age Wages
zhang3 18 300
li4 25 3500
wang5 22 3200
- stay li4 Insert a worker before , The message is : full name :zhao6, Age :24, Wages 3300
- Delete wang5 Information about
- utilize for Loop traversal , Print List Information about all workers in the
static void Main(string[] args)
{
//1.
// Complete the following requirements
//1) Create a List, stay List Add three workers to the , The basic information is as follows :
// full name Age Wages
//zhang3 18 300
//li4 25 3500
//wang5 22 3200
List<Worker> list = new List<Worker>();
Worker w1 = new Worker("zhang3", 18, 300);
Worker w2 = new Worker("li4", 25, 3500);
Worker w3 = new Worker("wang5", 22, 3200);
list.Add(w1);
list.Add(w2);
list.Add(w3);
//2) stay li4 Insert a worker before , The message is : full name :zhao6, Age :24, Wages 3300
list.Insert(1, new Worker("zhao6", 24, 3300));
//3) Delete wang5 Information about
list.RemoveAt(3);
//4) utilize for Loop traversal , Print List Information about all workers in the
for (int i = 0; i < list.Count; i++)
{
list[i].work();
}
}
3. There are the following List
List<Student> list = new List<Student>();
list.add(new Student(“Tom”, 18, 100, “class05”));
list.add(new Student(“Jerry”, 22, 70, “class04”));
list.add(new Student(“Owen”, 25, 90, “class05”));
list.add(new Student(“Jim”, 30, 80, “class05”));
list.add(new Student(“Steve”, 28, 66, “class06”));
list.add(new Student(“Kevin”, 24, 100, “class04”));
In this list On the basis of , Complete the following requirements :
1) Calculate the average age of all students
2) Calculate the average score of each class
class Student
{
public string name;
public int age;
public double score;
public string classNum;// Class number
public Student(string v1, int v2, int v3, string v4)
{
this.name = v1;
this.age = v2;
this.score = v3;
this.classNum = v4;
}
}
static void Main(string[] args)
{
//1) Calculate the average age of all students
List<Student> list2 = new List<Student>();
list2.Add(new Student("Tom", 18, 100, "class05"));
list2.Add(new Student("Jerry", 22, 70, "class04"));
list2.Add(new Student("Owen", 25, 90, "class05"));
list2.Add(new Student("Jim", 30, 80, "class05"));
list2.Add(new Student("Steve", 28, 66, "class06"));
list2.Add(new Student("Kevin", 24, 100, "class04"));
int sum = 0;
for (int i = 0; i < list2.Count; i++)
{
sum+= list2[i].age;
}
Console.WriteLine(" Average age :"+sum/list2.Count);
//2) Calculate the average score of each class
int a = 0;
double sum1 = 0;
int b = 0;
double sum2 = 0;
int c = 0;
double sum3 = 0;
for (int i = 0; i < list2.Count; i++)
{
if (list2[i].classNum =="class05")
{
sum1 += list2[i].score;
a++;
}
else if(list2[i].classNum == "class04")
{
sum2 += list2[i].score;
b++;
}
else if (list2[i].classNum == "class06")
{
sum3 += list2[i].score;
c++;
}
}
Console.WriteLine("class04 Class average :"+sum1/a);
Console.WriteLine("class05 Class average :"+sum2/b);
Console.WriteLine("class06 Class average :"+sum3/c);
}
版权声明
本文为[C # primary advanced]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220621093731.html
边栏推荐
- Node configuration environment CMD does not take effect
- Experiment 6 input / output stream
- ThreadLocal 测试多线程变量实例
- 打卡:4.23 C语言篇 -(1)初识C语言 - (12)结构体
- 超好用的【通用Excel导入功能】
- 《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
- Using jsonserialize to realize data type conversion gracefully
- 2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
- Fundamentals of software testing and development
- JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
猜你喜欢

【无标题】

研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台

. net webapi access authorization mechanism and process design (header token + redis)

超好用的【通用Excel导入功能】

QT dynamic translation of Chinese and English languages

手机连接电脑后,QT的QDIR怎么读取手机文件路径

Why is bi so important to enterprises?

二进制文件版本控制工具选择难?看完这篇你会找到答案

Course design of Database Principle -- material distribution management system

Top ten project management software similar to JIRA
随机推荐
[Mysql] LEFT函數 | RIGHT函數
Téléchargement en vrac de fichiers - téléchargement après compression
Fiddler use
JSON related
ThreadLocal 测试多线程变量实例
超好用的Excel异步导出功能
Flink实时数仓项目—DWS层设计与实现
Charles uses three ways to modify requests and responses
POI create and export Excel based on data
[mock data] fastmock dynamically returns the mock content according to the incoming parameters
一文了解全面静态代码分析
be based on. NETCORE development blog project starblog - (2) environment preparation and creation project
[MySQL] left function | right function
【VS Code】解决jupyter文件在vs code中显示异常的问题
手机连接电脑后,QT的QDIR怎么读取手机文件路径
通过 zxing 生成二维码
12. < tag linked list and common test site synthesis > - lt.234 palindrome linked list
Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
Detailed explanation of socket programming send() and recv() functions