Page 1 of 2
1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Sat Nov 18, 2006 8:14 pm
by bigaun
ลองฝึกทำเล่นๆ ครับ ให้เขียนเป็น คลาสนะครับ ใครทำเสร็จ ก็เอามาให้เพื่อนๆดูบ้างครับ
ให้เขียนโปรแกรม MyGrade โดยให้ผู้เขียนทําการรับค่าคะแนน 4 ค่าคือ
คะแนน quiz ครั้งที่ 1
คะแนน quiz ครั้งที่ 2
คะแนนสอบ Midterm
คะแนนปลายภาค
จากนั้นให้แสดงคะแนนรวมทั้งหมดที่ได้รับ และ เกรด โดยให้แสดงผลกรณีที่ได้เกรดต่างๆดังนี้
- กรณีคะแนน >= 90 คะแนนให้แสดงผลทางหน้าจอดังนี้
Total score is XX. Your grade is A. Congratulation, you are great!!!
- กรณีคะแนน >= 80 และ <= 89 คะแนนให้แสดงผลทางหน้าจอดังนี้
Total score is XX. Your grade is B. Good job!!
- กรณีคะแนน >= 70 และ <= 79 คะแนนให้แสดงผลทางหน้าจอดังนี้
Total score is XX. Your grade is C. Ok!!!
- กรณีคะแนน >= 60 และ <= 69 คะแนนให้แสดงผลทางหน้าจอดังนี้
Total score is XX. Your grade is D. You might have to retake this class again!!
- กรณีอื่นๆให้แสดงผลทางหน้าจอดังนี้
Total score is XX. Your grade is F. Sorry you Fail!!
หมายเหตุ XX คือคะแนนรวมทั้งหมดที่ได้
Posted:
Thu Nov 23, 2006 12:29 pm
by bigaun
/* Grade.h
*
* Author Mr.Prapas Rangnim
*
*/
class Grade
{
public:
Grade(){}
~Grade(){}
void showgrade();
void calGrade();
void setQuiz1(int score_quiz1);
int getQuiz1();
void setQuiz2(int score_quiz2);
int getQuiz2();
void setMidterm(int score_midterm);
int getMidterm();
void setFinal(int score_final);
int getFinal();
void setTotal(int score_total);
int getTotal();
private:
int quiz1;
int quiz2;
int midterm;
int final;
int total;
};
Posted:
Thu Nov 23, 2006 12:30 pm
by bigaun
/* Grade.cpp
*
* Author Mr.Prapas Rangnim
*
*/
#include "Grade.h"
#include <cstdlib>
#include <iostream>
using namespace std;
void Grade::showgrade()
{
if( getTotal()>= 90 )
{
cout<<"Total score is "
<<getTotal()
<<". Your grade is A. Congratulation, you are great!!! \n";
}
else
{
if ( (getTotal()>= 80) && (getTotal()<= 89))
{
cout<<"Total score is "
<<getTotal()
<<". Your grade is B. Good job!! \n";
}
else
{
if ( (getTotal()>= 70) && (getTotal()<= 79))
{
cout<<"Total score is "
<<getTotal()
<<". Your grade is C. Ok!!! \n";
}
else
{
if ( (getTotal()>= 60) && (getTotal()<= 69))
{
cout<<"Total score is "
<<getTotal()
<<". Your grade is D. You might have to retake this class again!! \n";
}
else
{
if ( (getTotal()>= 60) && (getTotal()<= 69))
{
cout<<"Total score is "
<<getTotal()
<<". Your grade is F. Sorry you Fail!! \n";
}
}
}
}
}
}
void Grade::calGrade()
{
int sumscore=0;
sumscore = getQuiz1()+getQuiz2()+getMidterm()+getFinal();
setTotal(sumscore);
}
void Grade::setQuiz1(int score_quiz1)
{
quiz1 = score_quiz1;
}
int Grade::getQuiz1()
{
return quiz1;
}
void Grade::setQuiz2(int score_quiz2)
{
quiz2 = score_quiz2;
}
int Grade::getQuiz2()
{
return quiz2;
}
void Grade::setMidterm(int score_midterm)
{
midterm = score_midterm;
}
int Grade::getMidterm()
{
return midterm;
}
void Grade::setFinal(int score_final)
{
final = score_final;
}
int Grade::getFinal()
{
return final;
}
void Grade::setTotal(int score_total)
{
total = score_total;
}
int Grade::getTotal()
{
return total;
}
Posted:
Thu Nov 23, 2006 12:40 pm
by bigaun
/* This is program for calculating grade.
*
* main.cpp
*
* Author Mr.Prapas Rangnim
*
*/
#include <cstdlib>
#include <iostream>
#include "Grade.h"
using namespace std;
int main(int argc, char *argv[])
{
Grade student;
int quiz1=0,quiz2=0,midterm=0,final=0;
cout<<"Enter Quiz 1 Score : ";
cin>>quiz1;
cout<<"Enter Quiz 2 Score : ";
cin>>quiz2;
cout<<"Enter MidTerm Score : ";
cin>>midterm;
cout<<"Enter Final Score : ";
cin>>final;
student.setQuiz1(quiz1);
student.setQuiz2(quiz2);
student.setMidterm(midterm);
student.setFinal(final);
student.calGrade();
student.showgrade();
system("PAUSE");
return EXIT_SUCCESS;
}
Posted:
Thu Nov 23, 2006 12:42 pm
by bigaun
มันไม่มีย่อหน้าให้อ่ะ
เลยอาจจะดูงง หน่อยนะ
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Sun Aug 03, 2008 12:45 am
by mailamok
ไม่เข้าใจอะ
ทำยังไง
ลองก็อปโค้ดไป
รันไม่ได้ คอมไพล์ไม่ผ่าน
ต้องทำยังไงก่อนอะงิ
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Sun Aug 03, 2008 8:21 pm
by HolyShadow
มันเป็นการเขียนโปรแกรมแบบ OO คือต้องแยกไฟล์เป็นสามไฟล์คือ main .cpp Grade.h(header file) Grade.cpp(implement file)
แล้วรันมันถึงจะททำงานได้
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Sun Aug 03, 2008 8:33 pm
by mailamok
HolyShadow wrote:มันเป็นการเขียนโปรแกรมแบบ OO คือต้องแยกไฟล์เป็นสามไฟล์คือ main .cpp Grade.h(header file) Grade.cpp(implement file)
แล้วรันมันถึงจะททำงานได้
ฮ่วย!!!
เครียด
งง
ไม่เข้าใจ
ขออย่างละเอียดค่ะ
มันเป็นวิธีการเขียนฟังก์ชั่นใช่มะงิ
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Sun Aug 03, 2008 9:49 pm
by HolyShadow
ขอละเอียดๆต้องไปนอกรอบแล้วละ
จิงๆถามพี่ๆคนไหนก็ได้แหละว่าเขียนโปรแกรมเปนคลาสทำยังไง
ปกติใช้dev-cเขียนโปรแกรมป่ะ
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Sun Aug 03, 2008 10:59 pm
by mailamok
ใช่ค่ะ
แต่ปกติไม่มีเวลาคุยจริงๆจังๆๆเป็นเรื่องเป็นราว (เป็นข่าวหน้าหนึ่ง อะ!!ไม่เกี่ยว)
กับพี่ๆซักกะที
มาเจอกระทู้นี้ ก็เลยฝากคำถามไว้ที่บอร์ดน่ะค่ะ
โอเครค่ะ ขอบคุณมากที่อุตส่าห์มาตอบให้นะคะ
เดี๋ยวจะลองถามรุ่นพี่ดูละกัน
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Thu Aug 07, 2008 12:29 pm
by bigaun
เผื่อน้องๆยังไม่ได้เรียนเรื่อง คลาส เลยเขียนแบบธรรมดามาให้ ลองดูล่ะกัน
- Code: Select all
#include<iostream>
using namespace std;
int main()
{
int quiz1=0,quiz2=0,midterm=0,final=0;
cout<<"Enter Quiz 1 Score : ";
cin>>quiz1;
cout<<"Enter Quiz 2 Score : ";
cin>>quiz2;
cout<<"Enter MidTerm Score : ";
cin>>midterm;
cout<<"Enter Final Score : ";
cin>>final;
/* calculate grade */
int total=0;
total = quiz1+quiz2+midterm+final;
/* show grade */
if( total >= 90 ){
cout<<"Total score is "<<total<<". Your grade is A. Congratulation, you are great!!! \n";
}//end if total >= 90
else{
if ( (total>= 80) && (total<= 89)){
cout<<"Total score is "<<total<<". Your grade is B. Good job!! \n";
}//end if ( (total>= 80) && (total<= 89))
else{
if ( (total>= 70) && (total<= 79)){
cout<<"Total score is "<<total<<". Your grade is C. Ok!!! \n";
}//end if ( (total>= 70) && (total<= 79))
else{
if ( (total>= 60) && (total<= 69)){
cout<<"Total score is "<<total<<". Your grade is D. You might have to retake this class again!! \n";
}//end if ( (total>= 60) && (total<= 69))
else{
if ( (total>= 60) && (total<= 69)){
cout<<"Total score is "<<total<<". Your grade is F. Sorry you Fail!! \n";
}//end if ( (total>= 60) && (total<= 69))
}
}
}
}
system ("pause") ;
return 0 ;
}
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Thu Aug 07, 2008 3:08 pm
by Inception
เย้ พี่อั๋นกลับมาแล้ว
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Thu Aug 07, 2008 4:04 pm
by mailamok
เย้ พี่อั๋นกลับมาแว้วววว
คิดถึง....
เข้าใจบ้างแล้ว
เย้
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Tue Aug 26, 2008 3:25 am
by jjmedz
noo-mai-binpaibinma wrote:ใช่ค่ะ
แต่ปกติไม่มีเวลาคุยจริงๆจังๆๆเป็นเรื่องเป็นราว (เป็นข่าวหน้าหนึ่ง อะ!!ไม่เกี่ยว)
กับพี่ๆซักกะที
มาเจอกระทู้นี้ ก็เลยฝากคำถามไว้ที่บอร์ดน่ะค่ะ
โอเครค่ะ ขอบคุณมากที่อุตส่าห์มาตอบให้นะคะ
เดี๋ยวจะลองถามรุ่นพี่ดูละกัน
ปลื้มใจแกจัง ดูตั้งใจเรียนดี
Re: 1.โปรแกรมคำนวณเกรด[input basic]
Posted:
Tue Aug 26, 2008 5:06 pm
by mailamok
ความตั้งใจ แปร ผกผันกะคะแนน T__T
เพราะความตั้งใจ แปร ผกผันกะ ปัญญา