当前位置:网站首页>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
边栏推荐
- Mysql database design specification
- yes. Net future
- 超好用的【通用Excel导入功能】
- QT uses drag and drop picture to control and mouse to move picture
- Chapter 7 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of modular programming exercises with functions
- Talent Plan 学习营初体验:交流+坚持 开源协作课程学习的不二路径
- QT dynamic translation of Chinese and English languages
- Supersocket is Use in net5 - startup
- Cefsharp stores cookies and reads cookies
- AWS from entry to actual combat: creating accounts
猜你喜欢

一套组合拳,打造一款 IDEA 护眼方案

Web Course Design - his system
![Super easy to use [general excel import function]](/img/9b/ef18d1b92848976b5a141af5f239b5.jpg)
Super easy to use [general excel import function]

Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer

12. < tag linked list and common test site synthesis > - lt.234 palindrome linked list

Super easy to use asynchronous export function of Excel

Problem a: face recognition

A set of combination boxing to create an idea eye protection scheme

Knowledge of software testing~

手机连接电脑后,QT的QDIR怎么读取手机文件路径
随机推荐
Cefsharp stores cookies and reads cookies
MySql分组查询规则
JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
手机连接电脑后,QT的QDIR怎么读取手机文件路径
Fiddler use
超好用的【通用Excel导入功能】
打卡:4.22 C语言篇 -(1)初识C语言 - (11)指针
研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台
Fundamentals of software testing and development
be based on. NETCORE development blog project starblog - (2) environment preparation and creation project
Super easy to use asynchronous export function of Excel
打卡:4.23 C语言篇 -(1)初识C语言 - (12)结构体
Course design of Database Principle -- material distribution management system
Detailed description of MySQL index [B + tree index, hash index, full-text index, overlay index]
socket编程 send()与 recv()函数详解
Blazor University (12) - component lifecycle
为什么BI对企业这么重要?
A set of combination boxing to create an idea eye protection scheme
It can receive multiple data type parameters - variable parameters
C introduction of variable parameter params