6.1

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace c6._1

{

public struct myDate

{

public int year;

public int month;

public int day;

public myDate(int y, int m, int d)

{

//必须全部赋值

year = y;

month = m;

day = d;

}

public void DisplayWeek()

{

Console.WriteLine("星期为:{0}", new DateTime(year, month, day).DayOfWeek);

}

public void DisplayData()

{

Console.WriteLine("日期为:{0}/{1}/{2}",year,month,day);

}

}

class Program

{

static void Main(string[] args)

{

Console.Write("请输入年:");

int y = int.Parse(Console.ReadLine());

Console.Write("请输入月:");

int m= int.Parse(Console.ReadLine());

Console.Write("请输入日:");

int d = int.Parse(Console.ReadLine());

myDate d1 = new myDate(y, m, d);

d1.DisplayData();

d1.DisplayWeek();

Console.ReadKey();

}

}

}

6.2

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace c6._2

{

public struct StudentGrade {

public string name;

public double score;

public StudentGrade(string n, double s)

{

name = n;

score = s;

}

public void Display() {

Console.WriteLine("名字:{0} ,成绩:{1}", name, score);

}

}

class Program

{

static void Main(string[] args)

{

//结构体初始化列表

StudentGrade[] stu =

{

new StudentGrade("张三",100),

new StudentGrade("李四",50),

new StudentGrade("王五",40),

new StudentGrade("赵六",60)

};

double sum = 0;

foreach(StudentGrade s in stu)

{

s.Display();

sum += s.score;

}

Console.WriteLine("平均分:{0}", sum / stu.Length);

Console.ReadKey();

}

}

}

6.3

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace c6._3

{

public struct Point {

public int x;

public int y;

public Point(int a,int b)

{

x=a;

y=b;

}

}

/*

public struct Triangle

{

Point a;

Point b;

Point c;

public Triangle(Point x,Point y,Point z){

a = x;

b = y;

c = z;

}

}

*/

class Program

{

static void Main(string[] args)

{

Point a = new Point();

Console.WriteLine("平面坐标点1:x={0},y={1}", a.x, a.y);

Point b = new Point(10, 12);

Console.WriteLine("平面坐标点2:x={0},y={1}", b.x, b.y);

Point c;

c.x = 22;

c.y=3;

Console.WriteLine("平面坐标点3:x={0},y={1}", c.x, c.y);

double side1 = Math.Sqrt(Math.Pow(a.x - b.x, 2) + Math.Pow(a.y - b.y, 2));

double side2 = Math.Sqrt(Math.Pow(a.x - c.x, 2) + Math.Pow(a.y - c.y, 2));

double side3 = Math.Sqrt(Math.Pow(b.x - c.x, 2) + Math.Pow(b.y - c.y, 2));

if (side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1)

{

double h = (side1 + side2 + side3) / 2;

double area = Math.Sqrt(h * (h - side1) * (h - side2) * (h - side3));

Console.WriteLine("三角形的面积:{0}", area);

}

else//两点重叠才不能构成三角形

Console.WriteLine("不能构成三角形");

Console.ReadKey();

}

}

}

6.4

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace c6._4

{

class Program

{

static void Main(string[] args)

{

Console.ForegroundColor = ConsoleColor.Cyan;

Console.WriteLine("前景色为Cyan");

Console.ResetColor();

Console.WriteLine("重置前景色");

Console.BackgroundColor = ConsoleColor.Red;

Console.WriteLine("背景色");

Console.ReadKey();

}

}

}

6.5

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace c6._5

{

class Program

{

//指明从1开始

enum Days { Monday = 1, Tuesday, Wednesday, Thursday, Firday = 5, Saturday, Sunday };

static void Main(string[] args)

{

Console.WriteLine("输入一个数字:1--7");

while (true)

{

try

{

int d = int.Parse(Console.ReadLine());

if (d > 7 || d < 1)

Console.WriteLine("输入的数字不对");

else

Console.WriteLine("{0}对应于{1}", d, (Days)d);

}

catch (FormatException e)

{

Console.WriteLine(e.Message);

break;

}

}

Console.ReadKey();

}

}

}

6.6

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace c6._6

{

class Program

{

enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Firday };

[FlagsAttribute]//指示枚举作为一组位域处理

//枚举值是有限制的

enum Colors { Red = 1, Green = 2, Blue = 8, Yello = 16 };

static void Main(string[] args)

{

//typeof用于获取类型

Type weekdays = typeof(Days);

Console.WriteLine("一周七天----对应枚举类型Days中的值:");

//Enum.GetNames检索指定枚举类型中常数名称的数组

foreach (string s in Enum.GetNames(weekdays))//真是神奇的c#啊

Console.WriteLine("{0,-11}={1}", s, Enum.Format(weekdays, Enum.Parse(weekdays, s), "d"));

Colors mcolor = Colors.Red | Colors.Blue | Colors.Yello;

Console.WriteLine("\n枚举变量mcolors存放如下颜色组合:{0}", mcolor);

Console.ReadKey();

}

}

}

6.7

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace c6._7

{

class Program

{

enum Colors {Red,Blue,White,Black};

static void Main(string[] args)

{

Console.WriteLine("4种颜色的球中取出3个不同色的球所有取法:");

int count = 0;

for(int i=0;i<4;i++)

for(int j=0;j<4;j++)

for (int k = 0; k < 4; k++)

{

if (i != j && i != k && k != j)

{

Console.WriteLine("{0}\t{1}\t{2}\t", (Colors)i, (Colors)j, (Colors)k);

count++;

}

}

Console.WriteLine("一共有{0}取法",count);

Console.ReadKey();

}

}

}

——————————————————————————————————————————————————

//写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。

author:royalchen

Email:royalchen@royalchen.com

———————————————————————————————————————————————————

python江红书后第六章实验答案_C#NET程序设计教程实验指导(清华大学江红,余青松)实验源码第六章...相关推荐

  1. python程序设计第七章答案_MOOC课程答案第七章单元测试答案_Python语言程序设计答案免费微信公众号...

    MOOC课程答案第七章单元测试答案_Python语言程序设计答案免费微信公众号 更多相关问题 [问答题,简答题] 什么叫仰视图? [问答题,简答题] 常见事故一般分为? [问答题,简答题] 进行气藏. ...

  2. Spring源码-AOP(六)-自动代理与DefaultAdvisorAutoProxyCreator

    2019独角兽企业重金招聘Python工程师标准>>> Spring AOP 源码解析系列,建议大家按顺序阅读,欢迎讨论 Spring源码-AOP(一)-代理模式 Spring源码- ...

  3. 试读angular源码第三章:初始化zone

    直接看人话总结 前言 承接上一章 项目地址 文章地址 angular 版本:8.0.0-rc.4 欢迎看看我的类angular框架 文章列表 试读angular源码第一章:开场与platformBro ...

  4. mybatis源码阅读(六) ---StatementHandler了解一下

    转载自  mybatis源码阅读(六) ---StatementHandler了解一下 StatementHandler类结构图与接口设计 BaseStatementHandler:一个抽象类,只是实 ...

  5. Celery 源码解析六:Events 的实现

    序列文章: Celery 源码解析一:Worker 启动流程概述 Celery 源码解析二:Worker 的执行引擎 Celery 源码解析三: Task 对象的实现 Celery 源码解析四: 定时 ...

  6. VB程序设计教程(第四版)龚沛曾 实验8-2

    VB程序设计教程(第四版)龚沛曾 实验8-2 将斐波那契数列的前10项写入文件Fb .dat,然后从该文件将数据读取出来并计算合计和平均数,最后送入列表框. 要求:文件数据格式如2.8.2所示,列表框 ...

  7. STM32毕业设计——基于STM32+JAVA+Android的六足机器人控制系统设计与实现(毕业论文+程序源码)——六足机器人控制系统

    基于STM32+JAVA+Android的六足机器人控制系统设计与实现(毕业论文+程序源码) 大家好,今天给大家介绍基于STM32+JAVA+Android的六足机器人控制系统设计与实现,文章末尾附有 ...

  8. 郑州大学python程序设计试题及答案_C 语言程序设计(2016 年秋季学期课程)

    C 语言的老师只会念 PPT?MOOC 课程只有视频,不如看书?感觉学懂了 C 语言,但设计不出程序?还在用谭老先生的书?感觉写法有点怪异?课堂上不敢问问题,怕自己被嘲笑?到计蒜客享受美国名校的教育方 ...

  9. Nacos源码系列——第二章(Nacos核心源码主线剖析下)

    上章节我这边带着大家看了下Nacos的源码,针对上节课做个总结: Nacos服务注册过程深度剖析 Nacos注册表如何防止多节点读写并发冲突 Nacos高并发支撑异步队列与内存队列剖析 Nacos心跳 ...

最新文章

  1. vs2005 下的发邮件代码
  2. 【大数据风控体系】理想大数据风控体系
  3. 微分求积:复化梯形、复化辛浦生
  4. [原创]位运算符实现两个整数加法运算
  5. 回溯法解决01背包问题
  6. Instagram:如何提升音乐音频质量?
  7. 史上最简洁易懂的PGP邮件加密教程(MAC OS X版)
  8. C# 内存的理解 通俗说
  9. 抱歉,程序员的工作不能用时间来衡量
  10. python调用函数_Python 函数中的 4 种参数类型
  11. Struts2增删改查 myeclipse开发文档加项目源码及eclipse开发项目源码
  12. RedHat Linux下Samba配置(简单配置)-转
  13. au6258引脚图及功能_电解电容引脚图/封装
  14. Windows 平台下Git 服务器搭建
  15. 序列化和反序列化(JSON、protobuf)
  16. iview的select联动_render函数渲染的iview中的Select组件如何联动?
  17. mgo EnsureIndex注意事项
  18. Windows下Python安装并为pip配置阿里镜像
  19. Android Things:外设I/O接口-GPIO
  20. Google搜索时如何在新标签页打开搜索结果

热门文章

  1. table表格加滚动条
  2. RPA学习-数据表处理
  3. android软件制作app下载地址,如何自己制作安卓apk软件?
  4. java计算机毕业设计志愿者管理系统演示录像2020源码+mysql数据库+系统+lw文档+部署
  5. CVPR 2018 | 8篇论文、10+Demo、双项挑战赛冠军,旷视科技掀起CVPR产学研交流热潮
  6. 【JVM】三色标记法
  7. WiFi模块(ESP8266)获取时间、天气API AT指令串口调试
  8. 川崎机器人here指令_川崎机器人定点修正坐标设置指导书.pdf
  9. android 密度像素,Android屏幕密度适配问题之px,dp,sp等详细介绍
  10. C语言小项目 扫雷游戏