반응형
using System;
class Absolute
{
public void getAbsolute(int a)
{
int b= 0;
if (a < 0) b= a * -1;
else b= a;
Console.WriteLine("{0}_{1}",a,b);
}
public void getAbsolute(float a)
{
float b = 0f;
if (a <0 ) b = a* -1;
else b=a;
Console.WriteLine("{0}_{1}",a,b);
}
public void getAbsolute(double a)
{
double b = 0;
if(a<0) b= a * -1;
else b = a;
Console.WriteLine("{0}_{1}",a,b);
}
public static void Main()
{
Absolute AB = new Absolute();
AB.getAbsolute(-23);
AB.getAbsolute(392.3f);
AB.getAbsolute(-293.2345634);
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace fTest
{
class Student
{
private string name="홍길동";
private int kor=0;
private int eng=0;
private int math=0;
public string nullChk(string read)
{
string str = read;
//Console.WriteLine("스트링의 값은{0}ㄹㅇㅁㄴㅁㄴ",str);
while(true)
{
if((str != ""))
return str;
Console.WriteLine("다시 입력하세요");
str = Console.ReadLine();
}
}
public void setStudent()
{
Console.Write("학생 성명을 입력하세요 --> ");
this.name = nullChk(Console.ReadLine());
Console.Write("국어 성적을 입력하세요 --> ");
this.kor = int.Parse(nullChk(Console.ReadLine()));
Console.Write("영어 성적을 입력하세요 --> ");
this.eng = int.Parse(nullChk(Console.ReadLine()));
Console.Write("수학 성적을 입력하세요 --> ");
this.math = int.Parse(nullChk(Console.ReadLine()));
}
public string print()
{
int sum=kor + eng + math;
float avg = sum / 3.0f;
Console.WriteLine("{0}의 종합점수는 --> {1}",this.name, sum);
Console.WriteLine("{0}의 종합점수는 --> {1:f2}",this.name, avg);
Console.WriteLine("{0}의 학점은 --> {1}",this.name, rank(avg));
Console.WriteLine("종료하시려면 'X or x'를 입력하시오.");
string sel = nullChk(Console.ReadLine());
return sel;
}
public char rank(float avg)
{
int intavg = (int)avg;
switch (intavg / 10)
{
case 10:
case 9: return 'A';
case 8: return 'B';
case 7: return 'C';
case 6: return 'D';
default: return 'F';
}
}
}// end class Student
class Program
{
static void Main(string[] args)
{
string tmp;
do
{
Student stu = new Student();
stu.setStudent();
tmp = stu.print();
if (tmp == "X" || tmp == "x")
break;
} while (true);
}
}
}
- Thanks 상봉
'.NET > C# Basic' 카테고리의 다른 글
C# 정정맴버 (0) | 2008.10.10 |
---|---|
클래스 관련 예제 (0) | 2008.10.10 |
상봉이 문제 (0) | 2008.10.09 |
정적맴버의 이해 인스턴스 (0) | 2008.10.08 |
C# 메서드 (0) | 2008.10.07 |
C# 배열 연산자 제어문 foreach (0) | 2008.10.06 |
c# ppt 4장 (0) | 2008.10.02 |
상철이 소스 (0) | 2008.10.02 |