C# 第1次实验报告:熟悉Visual Studio环境

C# 所有作业和实验报告

一、 实验目的及要求

  1. 熟悉Visual Studio编译环境。
  2. 掌握创建控制台应用程序的一般步骤。
  3. 初识C#程序结构,识记C#程序编写规范。

二、实验内容(或实验原理、实验拓扑)

  1. 让用户输入姓名 语文 数学 英语 三门课的成绩,然后给用户显示:XX,你的总成绩为XX分,平均成绩为XX分。(类型转换练习)

三、实验设备与环境

I7 7700HQ+16G内存+38TB分布式硬盘的笔记本电脑、Windows 10 1903政府版、Visual Studio 2019 企业版、.NET Framework 4.7.2

四、实验设计方案(包括实验步骤、设计思想、算法描述或开发流程等)

Created with Raphaël 2.2.0 Start Input name Input Chinese scores Input Math scores Input English scores Output : name, total scores, average scores End

五、实验结果(包括设计效果、测试数据、运行结果等)

Input name:
Coco
Your name is Coco.

Input Chinese scores :
100
Your Chinese scores is 100.

Input Math scores :
99
Your Math scores is 99.

Input English scores :
99
Your English scores is 99.

Dear Coco, your total scores is 298, your average scores is 99.33.

Press any key to quit.

六、实验小结(包括收获、心得体会、注意事项、存在问题及解决办法、建议等)

C#中decimal ,double,float的区别

NameCTS TypeDescriptionSignificant FiguresRange (approximate)
floatSystem.Single32-bit single-precision floating point7±1.5 × 10?45 to ±3.4 × 1038
doubleSystem.Double64-bit double-precision floating point15/16±5.0 × 10 ?324 to ±1.7 × 10308
decimalSystem.Decimal128-bit high precision decimal notation28±1.0 × 10?28 to ±7.9 × 1028
  • 如果我们在代码中写一个12.3,编译器会自动认为这个数是个double型。所以如果我们想指定12.3为float类型,那么你必须在数字后面加上F/f(Decimal加M/m)。
  • decimal类型用来表示高精度的浮点数,从上表可以看出,decimal的有效位数很大,达到了28位,但是表示的数据范围却比float和double类型小。decimal类型并不是C#中的基础类型,所以使用的时候会对计算时的性能有影响。
    定义一个decimal类型的浮点数:decimal d = 12.30M;

七、附录(包括作品、流程图、源程序及命令清单等)

本实验报告同步在:https://blog.csdn.net/COCO56/article/details/100633111

using System;

namespace Test1_2
{
    class Program
    {
        static void Main(string[] args)
        {
            //让用户输入姓名 语文 数学 英语 三门课的成绩,然后给用户显示:XX,你的总成绩为XX分,平均成绩为XX分。(类型转换练习)
            Console.WriteLine("Input name:");
            string name = Console.ReadLine();
            Console.WriteLine("Your name is " + name + ".");

            Console.WriteLine("\nInput Chinese scores :");
            decimal ChineseScores = Convert.ToDecimal(Console.ReadLine());
            Console.WriteLine("Your Chinese scores is " + ChineseScores + ".");

            Console.WriteLine("\nInput Math scores :");
            decimal MathScores = Convert.ToDecimal(Console.ReadLine());
            Console.WriteLine("Your Math scores is " + MathScores + ".");

            Console.WriteLine("\nInput English scores :");
            decimal EnglishScores = Convert.ToDecimal(Console.ReadLine());
            Console.WriteLine("Your English scores is " + EnglishScores + ".");

            decimal TotalScores = ChineseScores + MathScores + EnglishScores;
            decimal AverageScores = TotalScores / 3;
            AverageScores = Math.Round(AverageScores, 2);
            Console.WriteLine("\nDear {0}, your total scores is {1}, your average scores is {2}.", name, TotalScores, AverageScores);

            Console.WriteLine("\nPress any key to quit.");
            Console.ReadKey();
        }
    }
}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

COCO56(徐可可)

建议微信红包:xucoco56

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值