.NET--实验报告一

实验一C#程序设计基础

【实验目的】

1、了解.NET平台的知识,理解.NET基础体系结构和.NET程序的运行原理

2、掌握VisualStudio 2015安装及其使用

3、掌握C#控制台程序的基本结构以及数据类型、运算符、表达式和变量的含义与用法

4、掌握C#的基本语句,会使用顺序、选择、循环结构编写简单程序。

5、了解程序调试和异常处理概念,掌握利用VS调试程序的基本方法和技巧。

【实验内容】

1. Visual Studio 2015的安装与配置

在自己的计算机上安装Visual Studio 2015,并进行个性化设置。

2、简单程序设计

(1)任意输入一个三位整数,将其加密后输出密文,然后编写解密程序输出明文。方法是将该数每一位上的数字加9,然后除以10 取余,作为该位上的新数字,将第一位上的数字和第三位上的数字交换组成加密后的新数。

(2)体型判断。按“体指数”对肥胖程度进行划分: 体指数t = 体重w / (身高h)2  (w 单位为公斤,h单位为米)

l  当t <18时,为低体重;

l  当t介于18和25之间时,为正常体重;

l  当t介于25和27之间时,为超重体重;

l  当t >=27时,为肥胖。

编程从键盘输入你的身高h和体重w,根据给定公式计算体指数t,然后判断你的体重属于何种类型。

(3)从键盘输入若干个数,当遇到0时结束,输出其中正数和负数的平均值。

【实验过程】

2、简单程序设计

(1)加密解密三位数

核心代码入下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入百位数字:");
            int a1 = Convert.ToInt16(Console.ReadLine());
            Console.Write("请输入十位数字:");
            int b1 = Convert.ToInt16(Console.ReadLine());
            Console.Write("请输入个位数字:");
            int c1 = Convert.ToInt16(Console.ReadLine());
            int sum = a1 * 100 + b1 * 10 + c1;
            int d = (a1 + 9) % 10;
            int e = (b1 + 9) % 10;
            int f = (c1 + 9) % 10;
            int sum2 = f * 100 + e * 10 + d;
            Console.WriteLine("加密后的密文为:");
            Console.WriteLine(sum2);
            int sum3 = d * 100 + e * 10 + f;
            int a2;
            int b2;
            int c2;
            a2 = ((d + 10) - 9) % 10;
            b2 = ((e + 10) - 9) % 10;
            c2 = ((f + 10) - 9) % 10;
            int sum4 = a2 * 100 + b2 * 10 + c2;
            Console.WriteLine("解密后的明文:");
            Console.WriteLine(sum4);
        }
    }
}

运行结果如下:


(2)体型判断:

核心代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入体重/单位kg:");
            double w = Convert.ToDouble(Console.ReadLine()); 
            Console.Write("请输入身高/单位m:");
            double h = Convert.ToDouble(Console.ReadLine());
            double x = h * h;          
            double t =w/x;
            if (t<=18)
            {
                Console.WriteLine("对不起,你是低体重!");
            }
            else if(t>18 && t<=25)
            {
                Console.WriteLine("你的体重是正常的");
            }
            else if(t>25&&t<=27)
            {
                Console.WriteLine("对不起,你的体重超重!");
            }
            else
            {
                Console.WriteLine("对不起,你是肥胖体重!");
            }
        }
    }
}

运行结果如下:


哈哈0.0,我的体重不用减肥。

猜你喜欢

转载自blog.csdn.net/lijia111111/article/details/79638700
今日推荐