The Glorious Years of wisdom-c# basic 10 little Practice

Source: Internet
Author: User

Using system;using system.collections.generic;using system.linq;using System.text;namespace P03 Exercise {class Program {        static void Main (string[] args) {Test05 ();  } public static void Test01 () {/* Please write 1 methods to find the following rules for the number of columns: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...             The value of the specified number of digits. and returns the number * (the first 2 bits are 1, and the last 1 bits are the first 2 bits.)            */INT res = test01_1 (6);        Console.WriteLine (RES); public static int test01_1 (int plugnum) {//1. If the number of digits entered is <=2, return 1 if (Plugnum &L            T;= 2) return 1;            2. If it is greater than 2, then the operation int prev1 = 1;            int prev2 = 1;            int res = 0;                for (int i = 1; I <= plugNum-2; i++) {res = prev1 + prev2;                Prev1 = Prev2;            Prev2 = res;        } return res; The public static void Test02 () {/* 2. Write 1 methods that receive the radius of the circle. Returns the area and perimeter of the circle. The area of the round is 3.14 =π*The square of the radius, the circumference of the circle =π* the radius (10 points) */float[] Arrresult = new float[2];//subscript 0 for area; subscript 1 for Perimeter test02_01 (5, AR            Rresult);        Console.WriteLine (the area of the circle with radius {0} is {1}, Perimeter is {2} ", 5, arrresult[0], arrresult[1]);        }//<summary>//Calculate perimeter and area///</summary>//<returns></returns>            public static void test02_01 (int half, float [] arr) {Arr[0] = 3.14f * half * half;        ARR[1] = 2 * 3.14f * HALF; } public static void Test03_01 () {/* Please write 1 programs that receive the user's input class number from the console, and then receive the results of each of the 1 individuals from the console respectively. As long as there are 1 of the results are not legal (not The user is prompted to re-enter the student's score in the range of 0-100 or the input is not an integer. When all the students ' grades have been entered, print out the average of the class, then ask for the average score of 1 points and remove the 1 lowest points, and then print the scores from high to low.            (25 points) */Console.WriteLine ("Number of students received:"); int max = 0;//highest int min = 0;//min int scoretotal = 0;//total score int count = Int.   Parse (Console.ReadLine ());//Total number of int[] Arrscore = new int[count];//Fractional array         for (int i = 0; i < count; i++) {int score = test03_01_01 ("Please enter" + (i + 1) + "Student's score                :");                Arrscore[i] = score;                    if (i = = 0) {max = score;                min = score;                } scoretotal + = score;//Join total if (Max < score) max = score;//Determine whether the highest score within this cycle if (min > Score) min = score;//Determines whether the lowest score within this cycle is the float avg0 = (scoretotal-max-min) * 1.0f            /(COUNT-2);            1.0 sort List<int> List = Arrscore.tolist (); List.            Sort ();                Console.WriteLine ("The total number is {0}, the class is divided into {1}, the average of the lowest score after the highest score is divided into {2}", Count, Scoretotal * 1.0f/count,            AVG0);            Console.WriteLine ("Show score from low to High:");            foreach (int i in list) {Console.WriteLine (i); }}//Prompt the user to enter a numeric value for an integer type, and must be between 1-100 public static int test03_01_01 (string strMsg) {int res =-1;                while (true) {Console.WriteLine (STRMSG);                String str = Console.ReadLine (); if (int. TryParse (str, out res))//Convert the user input string into a value {if (res >= 0 && Res <= 100)//judgment number                    The value knows whether the number is 0-100 between {break; } else {Console.WriteLine ("must be a numeric value between 0-100!                    "); }} else {Console.WriteLine ("The value must be entered ~~!                ");        }} return res;            } public static void Test04 () {/* Write a program, enter a user name and password, implement the function of the user login program, at most allow input three times, more than three times not allowed to log in and quit the program */            String okname = "";            String okpwd = "";            int i = 0; while (true) {Console.WriteLine ("Please enter your user name:");                Okname = Console.ReadLine ();                Console.WriteLine ("Please enter your password:");                Okpwd = Console.ReadLine (); if (Okname = = "James" && okpwd = = "123") {Console.WriteLine ("User Login succeeded ~~~!                    ");                Break } else {Console.WriteLine ("Username or password input error ~~!                    ");                    i++;                        if (I >= 3) {Console.WriteLine ("Sorry, you have entered more than 3 times the program exits ~ ~");                        Console.ReadLine ();                    Break }}}} public static void Test05 () {/* * * has 1 integers              Array, assuming that the values for each of the 1 elements are 1 positive integers (meaning that the values for every 1 elements are greater than 0).             * Write 1 methods that remove duplicate elements from the array and return 1 arrays with no duplicate data. * For example: have array a={1,2,3,3,4,4,5,6,6}, method returns 1 new array b={1,2,3,4,5,6} */int[] arr = {1, 2, 100, 99, 99, 88, 77, 3, 3, 4, 4, 5, 6, 6, 99};        int[] arrnew = Getanewarr (arr); } public static int[] Getanewarr (int[] arr) {int[] arrtemp = new Int[arr.            Length]; int indexnum = 0;//records the number of distinct values//1. Loop to find the values that are not duplicated in the temporary array for (int i = 0; i < arr. Length; i++) {int num = arr[i];//takes out a value in the source array bool Isexist = false;//Record Whether the number is in a temporary array                    There is a for (int j = 0; J < Arrtemp.length, j + +)//Use the values in the source array to compare to the temporary array, if not the same, mark {                    if (arrtemp[j] = = num) {isexist = true; }} if (!isexist)//If the original array value does not exist in the temporary array, save to the temporary array {Arrte                    Mp[indexnum] = Arr[i]; indexnum++;//increment the number of non-repeating values}}//2. Create a new array int [] arrnew = new, according to the number of distinct values found            Int[indexnum]; 2.1 Copy non-repeating values from the temporary array to the new numberGroup for (int i = 0; i < Indexnum; i++) {arrnew[i] = Arrtemp[i];        }//2.2 returns the new array return arrnew; }    }}

  

Using system;using system.collections.generic;using system.linq;using System.text;namespace P04 Exercise {class Program {        static void Main (string[] args) {console.readline (); } public static void No1 () {/* * Defines 1 car classes, has brand wheel quantity color price model seat Number field, * has 1 Driving methods, * There are 1 ways to stop * There is also a way to introduce yourself (show your own brand wheel color price model seat.             Information.);             * Create objects and test them.            */Qiche QicheNo1 = new Qiche ();            Qicheno1.xingshi ();        Qicheno1.tingzhi ();            } public static void No2 () {Student stu = new Student (); Stu.            Name = ""; */* Define 1 student classes, with name, age, cell phone number, school number four attributes, the student's name must not be empty string, and the length can not be less than 2, otherwise the default value is "Nameless", age can only be 0-10 0, otherwise the default value is 18, and the mobile phone number can only be 11 digits.                Otherwise, the default value of 13444444444 is required to be 10 digits, otherwise the assignment is the default value of "0000000000".                Then define 1 ways to introduce yourself and print out your name and age mobile number. Then define 1 teacher classes, and the teacher class also has the name ageMobile phone number three attribute requirements are the same as the student class, but the teacher class also has 1 attributes for the salary requirement value of 1000-2000, otherwise the default value is 1000, and the teacher also has to introduce his own method (show all information about himself name age sex (not paid) */}}}

auto class

using system;using system.collections.generic;using System.Linq;using System.text;namespace P04 Practice {//<summary>/////</summary> public class Qiche {PR        Ivate string Pinpai;        private int Lunzishuliang;        private string Yanse;  #region 1.0 Driving Methods +void Xingshi ()//<summary>/////</summary> public void        Xingshi () {Console.WriteLine ("Car on drive ~ ~ ~"); } #endregion #region 2.0 Stop Method Brake +void Tingzhi ()///<summary>//Stop method brakes////        lt;/summary> public void Tingzhi () {Console.WriteLine ("The car is stopping ~ ~ ~"); } #endregion #region 3.0 Introduce yourself void Show ()///<summary>//3.0 Introduce yourself///</S ummary> public void Show () {} #endregion}} 

  Student class

Using system;using system.collections.generic;using system.linq;using system.text;namespace P04 Practice {//    < Summary>///Student class//</summary> public class    Student    {        private int id;        private string name;        private int age;        private int cellphone;        #region 1.0 Name +string name////<summary>//////        </summary> public        string name        {            get {return name;}            Set            {                if (string. IsNullOrEmpty (value) | | Value. Length < 2)                {                    name = "Nameless";                }                else                {                    name = value;         }}} #endregion    }}

  

Calculator

Using system;using system.collections.generic;using system.linq;using system.text;namespace P05 Calculator {public    enum Cultype    {        Jia = 1,        Jian = 2,        Chen = 3,        Chu = 4}    }

  

Using system;using system.collections.generic;using system.linq;using system.text;namespace P05 Calculator {//<summary&    Gt Calculator///</summary> public class Jisuanqi {#region 1.0 calculation +void Jisuan ()///<summary&        Gt            1.0 calculation///</summary> public void Jisuan () {//1. Requires user input operation symbol +,-, *,/            Console.Write ("Please enter operator (1+,2-,3*,4/):"); int curtype = Int.            Parse (Console.ReadLine ());            2. Receive the first value Console.WriteLine ("Please enter the first value:"); int numA = Int.            Parse (Console.ReadLine ());            3. Receive the second value Console.WriteLine ("Please enter a second value:"); int numB = Int.            Parse (Console.ReadLine ());            Operation result int res =-1;            4. Operate according to operator Cultype type = (Cultype) curtype;                        #region operation of the switch (type) {case Cultype.jia according to the operator: {          res = NumA + NumB;              Break                        } case Cultype.jian: {res = numa-numb;                    Break                        } case Cultype.chen: {res = NumA * NumB;                    Break                        } case Cultype.chu: {res = numa/numb;                    Break        }} #endregion Console.WriteLine ("{0} {1} {2}={3}", NumA, Getopename (type), NumB, res);        } #endregion #region 1.1 returns the corresponding operation symbol based on the enumeration-string getopename (Cultype type)//<summary> 1.1 returns the corresponding operation symbol based on the enumeration///</summary>//<param name= "type" ></param>//&L            T;returns></returns> string Getopename (Cultype type) {string name = "";       Switch (type) {         Case Cultype.jia: {name = "+";                    Break                        } case Cultype.jian: {name = "-";                    Break                        } case cultype.chen: {name = "*";                    Break                        } case Cultype.chu: {name = "/";                    Break        }} return name; } #endregion}}

  

Using system;using system.collections.generic;using system.linq;using system.text;namespace P05 Calculator {    class Program    {        static void Main (string[] args)        {            Jisuanqi jsq = new Jisuanqi ();            Jsq. Jisuan ();            Console.ReadLine ();}}}    

  

The Glorious Years of wisdom-c# basic 10 little Practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.