관리 메뉴

bread, coffee and coding

C# D+3 본문

C#

C# D+3

DongJin lee 2021. 7. 5. 21:34

[절차적 프로그래밍]

1. 변수, 상수
2. 자료형(Type) -- byte, short, int, float, double, string
3. 조건문 (if, switch..), 반복문 (while, for, do_while ...)
4. 함수 -- 함수타입(return), 함수 이름
Call by Value, Call by Reference
<매개변수,파라미터, 인자값>


5. 배열(자료구조), LinkedList Tree, Stack, Queue ...


[객체지향 프로그래밍]

1.캡슐화, 추상화
2.다형성(오버로딩, 오버라이딩)
3.상속
-----------------------------------------------------
4.인터페이스(interface)
5.Wrapper Class
6.깊은 복사, 얇은 복사
7. Boxing, UnBoxing
....

[관점지향 프로그래밍]
AOP
1. Aspcet
--------------------------------------------------------
----------------------------0----------------------------
디자인패턴(Design Patte)


함수를 만들때 어디에 class 안쪽 메인 밖에 쪽에 하는것이 좋다



if (n < 2)
 return n;
 else
  return Fibonacci(n - 1) + Fibonacci(n - 2); //재귀함수 


-------------------------------------------------------------------
using System;

namespace ConsoleApp6
{
    class Calculator
    {
        public static int ThreePlus(int a, int b, int c)   //static이 중요하다 
        { 
            return a +b + c;
        }

        static void Main(string[] args)
        {
            int result = ThreePlus(2, 4, 6);

            Console.WriteLine(result);

        }
    }
}
---------------------------------------------------------------------------
문제 이름과 나이를 매개변수로 받으면 다음과 같이 출력하는 함수를 만들어주세요
Personinfo(“홍길동”, 22);
Console.WriteLine(str);  // 이름은 홍길동 나이는 22살입니다.


using System;

namespace ConsoleApp6
{
    class Calculator
    {
        public static string Personinfo(string name, int age) 
        {
            return "이름은" + name + "나이는 " + age + "살입니다";
        }


        static void Main(string[] args)
        {
            string str  = Personinfo("홍길동",22);

            Console.WriteLine(str);

        }
    }
}

----------------------------------------------------------------------------
p191

using System;

namespace ConsoleApp6
{
    class Calculator
    {
        static int Fibonacci(int n)
        {
            if (n < 2)
                return n;
            else
                return Fibonacci(n - 1) + Fibonacci(n - 2);
        }
        static void PrintProfile(string name, string phone)
        {
            if (name == "")
            {

                Console.WriteLine("이름을 입력해주세요");
                return;
            }
            Console.WriteLine($"Name:{name}, Phone:{phone}");
        }
        

        static void Main(string[] args)
        {
            Console.WriteLine($"10번째 피나보치수 : { Fibonacci(10)}");

            PrintProfile("", "123-4567 ");

        }

       
    }
}

-------------------------------------------------------------------------

using System;

namespace ConsoleApp6
{
    class Calculator
    {
        static int Fibonacci(int n)
        {
            if (n < 2)
                return n;
            else
                return Fibonacci(n - 1) + Fibonacci(n - 2);
        }
        static void PrintProfile(string name, string phone)
        {
            if (name == "")
            {

                Console.WriteLine("이름을 입력해주세요");
                return;
            }
            Console.WriteLine($"Name:{name}, Phone:{phone}");
        }
        

        static void Main(string[] args)
        {
            Console.WriteLine($"10번째 피나보치수 : { Fibonacci(10)}");

            PrintProfile("", "123-4567 ");

        }

       
    }
}


-----------------------------------------------------------------------


using System;

namespace ConsoleApp6
{
    class Calculator
    {
        static void Test()
        {
            Console.WriteLine("Test");

        }
        static void Main(string[] ages)
        {
            //Program p = new Progrm(); //메모리 할당, 객체생성
            Test();
            Calculator.Test(); //static 메소드 클래스 이름, 메소드 사용 
           
        }
        

       
    }
}

----------------------------------------------------------------------
using System;

namespace MyApp_Recurssive02
{
    class Program
    {
        static int Func(int n)
        {
            if (n < 1)
            {
                Console.WriteLine("Func1 : {0}", n);
                return n;
            }
                
            else
            {
                Console.WriteLine("Func2 : {0}", n);
                return Func(n - 1);
            }
        }

        static void Main(string[] args)
        {
            Console.WriteLine("결과값:{0}",Func(100));

        }
    }
}
----------------------------------------------------------
using System;

namespace MyApp_Recurssive02
{
    class Program
    {
        static int Func(int n)
        {
            Console.WriteLine(n);
            return Func(n + 1);

        }
        static void Main(string[] args)
        {
                Func(1);

        }
    }
}

----------------------------------------------------------------
x 의 y 거듭제곱을 구하는 문제이다.

2 10 을 입력 받으면 2 의 10 거듭제곱 1024 가 출력되어야 한다.

2^10 = 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2=1024
입력
두 정수 x , y 가 입력된다.

출력
x 의 y 거듭제곱된 결과값을 출력한다.

출력 결과는 정수 범위( 2^31 - 1)를 넘지 않는다.

입출력 예
입력

2 10

출력

1024

using System;

namespace MyApp_Recurssive02
{
    class Program
    {
        static int powerofx(int n)
        {
            if (n < 1)
                return 1;
            else
                return 2 * powerofx(n - 1);
            
        }
        static void Main(string[] args)
        {
            
            Console.WriteLine(powerofx(10));
          

        }
        
    }
}
-------------------------------------------------------------------

using System;

namespace MyApp_p98_StringSlice
{
    class Program
    {
        static void Main(string[] args)
        {
            string greeting = "Good Morning";

            Console.WriteLine(greeting.Substring(0, 5));
            Console.WriteLine(greeting.Substring(5));
            Console.WriteLine();

            string[] arr = greeting.Split(new string[] { " " }, StringSplitOptions.None);
            Console.WriteLine("Word count : {0}", arr.Length);

            foreach (string element in arr)
                Console.WriteLine("{0}", element);
        }
    }
}

공백 단위로 // {" "} 안에 콤마를 적으면 콤마 단위로 잘라준다

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
using System;

namespace MyApp_03_Format
{
    class Program
    {
        static void Main(string[] args)
        {
            // Console.WriteLine("Total: {0, 7:D}", 123);
            string result = string.Format("{0}DEF", "ABC");
            Console.WriteLine(result);

            string result2 = string.Format("{0,10}DEF", "ABC");
            Console.WriteLine(result2);

            string result3 = string.Format("{0,-10}DEF", "ABC"); // /t
            Console.WriteLine(result3);
        }
    }
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

using System;

namespace MyApp_03_Format
{
    class Program
    {
        static void Main(string[] args)
        {
            // Console.WriteLine("Total: {0, 7:D}", 123);
            string result = string.Format("{0}DEF", "ABC");
            Console.WriteLine(result);

            string result2 = string.Format("{0,10}DEF", "ABC");
            Console.WriteLine(result2);

            string result3 = string.Format("{0,-10}DEF", "ABC"); // /t
            Console.WriteLine(result3);

            Console.WriteLine("{0:D}", 255); //D 십진수
            Console.WriteLine("{0:D}", 0xFF); //D 십진수

            Console.WriteLine("{0:X}", 255); //16진수 
            Console.WriteLine("{0:X}", 0xFF); //16진수


            Console.WriteLine("{0:N}", 123456789);

            Console.WriteLine("고정소수점: {0:F}", 1234.45);
            Console.WriteLine("공학:{0:E}", 123.456789);






        }
    }
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
using System;
using System.Globalization;

namespace MyApp_Date_Format
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2018, 11, 3, 23, 18, 22);

            //12시간형식
            Console.WriteLine("12형식:{0:yyyy-mm-dd tt hh:mm:ss (ddd)}", dt);

            Console.WriteLine("12시간 형식: {0:(ddd}", dt);
            //24시간형싱
            Console.WriteLine("12시간 형식:{0:yyyy-MM-dd HH:mm:ss (ddd)}", dt);

            CultureInfo ciKo = new CultureInfo("en-US");

            Console.WriteLine(dt.ToString("yyyy-MM-dd tt hh:mm:ss(ddd)", ciKo));

        }
    }
}

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
using System;

namespace Myapp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("{0} {1}", 123, " 최강삼성 ");
            Console.WriteLine($"{123} {"최강삼성"}");

            Console.WriteLine("{0, -10:D5}",123);
            Console.WriteLine($"{123,-10:D5}");

            int n = 123;
            Console.WriteLine("{0}", n > 100 ? "큼" : "작음"); //ture 면 앞 false 뒷값
            Console.WriteLine($"{(n > 100 ? "큼" : "작음")}");
        }
    }
}

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

using System;

namespace Myapp
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = 3;

            if (number > 0)
            {
                if (number % 2 == 0)
                    Console.WriteLine("0보다 큰 짝수");
                else
                    Console.WriteLine("0보다 큰 홀수");

            }
            else if (number == 0)
            {
                Console.WriteLine("0 입니다.");
            }
            else
                Console.WriteLine("0보다 작은 값입니다.");
        }

    }
}

-----------------------------------------------------

성적을 입력하면 학점을 출력합니다
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
90~100까지 A 학점
80~89까지 B 학점
70~79까지 C학점
60~69까지 D학점
59점이하 F

점수: 93
A 학점입니다.
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
점수: 89
B 학점입니다
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ


'C#' 카테고리의 다른 글

C# D+5  (0) 2021.07.05
C# D+4  (0) 2021.07.05
C# D+2  (0) 2021.07.05
C# D+1  (0) 2021.05.05