ข่าว IT ล่าสุด
ถูกใจอย่าลืม Like Fanpage
ใครก็ได้ช่วยหน่อยคร้าบ
แสดงแล้ว 4299 ครั้ง /
มกราคม 31, 2010, 08:41:23

jittatarn

ออฟไลน์
กระทู้ : 3
คะแนนขอบคุณ : 0
พอดีอาจารย์ให้เขียนโปรเเกรมpascal
9โปรเเกรมหลักเเล้วมีโปรเเกรมย่อยเท่าไรก็ได้
เช่นโปรเเกรมหลักที่1เกี่ยวกับคณิตศาสตร์ไรเงี้ยอะครับ
โปรเเกรม2เกี่ยวกับฟิสิกส์
รบกวนช่วยเขียนให้หน่อยนะครับ
 :-X


jittatarn

ออฟไลน์
กระทู้ : 3
คะแนนขอบคุณ : 0
มกราคม 31, 2010, 08:56:34
เอาเป็นโปรเเกรมเครื่องคิดเลขก้อได้ครับ
โปรเเกรมหลักที่1 เป็นการบวก
โปรเเกรมหลักที่2 เป็นการลบ
โปรเเกรมหลักที่3 เป็นการคูณ
โปรเเกรมหลักที่4 เป็นการหาร
โปรเเกรมหลักที่5 เป็นการยกกำลังสอง
โปรเเกรมหลักที่6 เป็นการถอดรากที่สอง
โปรเเกรมหลักที่7 พื้นที่สามเหลี่ยม
โปรเเกรมหลักที่8 พื้นที่วงกลม
โปรเเกรมหลักที่9 พื้นที่สี่เหลี่ยม
ใส่อยู่ในอันเดียวกันหมดอะครับ
เห็นมีอยู่ในแบบฝึกหัดตัวอย่างเเต่ทำมารวมกันไม่เป็น
เเล้วพอออกก้อใช้เลข0ในการออก

jittatarn

ออฟไลน์
กระทู้ : 3
คะแนนขอบคุณ : 0
มกราคม 31, 2010, 09:45:43

program Calculation;
uses crt;
var menu,n1,n2: integer;

function p(n1,n2: integer): real;
begin
  p:=n1+n2;
end;

function mi(n1,n2: integer): real;
begin
  mi:=n1-n2;
end;

function mul(n1,n2: integer): real;
begin
  mul:=n1*n2;
end;

function divi(n1,n2: integer): real;
begin
  divi:=n1/n2;
end;

function sqroot(n1: integer): real;
begin
  sqroot:=sqrt(n1);
end;

function sqpow(n1: integer): real;
begin
  sqpow:=sqr(n1);
end;

{PROCEDURE}

procedure table;
var tn: integer;
    q: char;
begin
  repeat
  clrscr;
  writeln('Multiply Table');
  writeln;
  write('Put a number : ');
  readln(tn);
  clrscr;
  writeln(tn,' x 1 = ',tn*1);
  writeln(tn,' x 2 = ',tn*2);
  writeln(tn,' x 3 = ',tn*3);
  writeln(tn,' x 4 = ',tn*4);
  writeln(tn,' x 5 = ',tn*5);
  writeln(tn,' x 6 = ',tn*6);
  writeln(tn,' x 7 = ',tn*7);
  writeln(tn,' x 8 = ',tn*8);
  writeln(tn,' x 9 = ',tn*9);
  writeln(tn,' x 10 = ',tn*10);
  writeln(tn,' x 11 = ',tn*11);
  writeln(tn,' x 12 = ',tn*12);
  repeat
  writeln;
  write('Return to Main Menu? (y/n) : ');
  readln(q);
  if (q='y') or (q='n') then begin writeln; end
  else begin writeln('Invalid Choice');
       end;
  until (q='y') or (q='n');
  until q='y';
end;

procedure plus;
var q: char;
begin
  repeat
  clrscr;
  writeln('Plus Calculation');
  writeln;
  write('Put first number : ');
  readln(n1);
  writeln;
  write('Put second number : ');
  readln(n2);
  writeln;
  writeln;
  writeln(n1,' + ',n2,' = ',p(n1,n2):9:2);
  repeat
  writeln;
  write('Return to Main Menu? (y/n) : ');
  readln(q);
  if (q='y') or (q='n') then begin writeln; end
  else begin writeln('Invalid Choice');
       end;
  until (q='y') or (q='n');
  until q='y';
end;

procedure minus;
var q: char;
begin
  repeat
  clrscr;
  writeln('Minus Calculation');
  writeln;
  write('Put first number : ');
  readln(n1);
  writeln;
  write('Put second number : ');
  readln(n2);
  writeln;
  writeln;
  writeln(n1,' - ',n2,' = ',mi(n1,n2):9:2);
  repeat
  writeln;
  write('Return to Main Menu? (y/n) : ');
  readln(q);
  if (q='y') or (q='n') then begin writeln; end
  else begin writeln('Invalid Choice');
       end;
  until (q='y') or (q='n');
  until q='y';
end;

procedure multi;
var q: char;
begin
  repeat
  clrscr;
  writeln('Multiply Calculation');
  writeln;
  write('Put first number : ');
  readln(n1);
  writeln;
  write('Put second number : ');
  readln(n2);
  writeln;
  writeln;
  writeln(n1,' x ',n2,' = ',mul(n1,n2):9:2);
  repeat
  writeln;
  write('Return to Main Menu? (y/n) : ');
  readln(q);
  if (q='y') or (q='n') then begin writeln; end
  else begin writeln('Invalid Choice');
       end;
  until (q='y') or (q='n');
  until q='y';
end;

procedure divide;
var q: char;
begin
  repeat
  clrscr;
  writeln('Divide Calculation');
  writeln;
  write('Put first number : ');
  readln(n1);
  writeln;
  write('Put second number : ');
  readln(n2);
  writeln;
  writeln;
  writeln(n1,' / ',n2,' = ',divi(n1,n2):9:2);
  repeat
  writeln;
  write('Return to Main Menu? (y/n) : ');
  readln(q);
  if (q='y') or (q='n') then begin writeln; end
  else begin writeln('Invalid Choice');
       end;
  until (q='y') or (q='n');
  until q='y';
end;

procedure sqt;
var q: char;
begin
  repeat
  clrscr;
  writeln('Square Root Calculation');
  writeln;
  write('Put a number : ');
  readln(n1);
  writeln;
  writeln('Square Root of ',n1,' is ',sqroot(n1):9:2);
  repeat
  writeln;
  write('Return to Main Menu? (y/n) : ');
  readln(q);
  if (q='y') or (q='n') then begin writeln; end
  else begin writeln('Invalid Choice');
       end;
  until (q='y') or (q='n');
  until q='y';
end;

procedure sq;
var q: char;
begin
  repeat
  clrscr;
  writeln('Square Power Calculation');
  writeln;
  write('Put a number : ');
  readln(n1);
  writeln;
  writeln('Square Power of ',n1,' is ',sqpow(n1):9:2);
  repeat
  writeln;
  write('Return to Main Menu? (y/n) : ');
  readln(q);
  if (q='y') or (q='n') then begin writeln; end
  else begin writeln('Invalid Choice');
       end;
  until (q='y') or (q='n');
  until q='y';
end;

procedure circle;
var r: char;
    area: real;
begin
     clrscr;
     write('input you reader = ');
     readln(r);
     area:=3.14;
     writeln('this area of circle = ',area:1:2);
     readln;
end;
procedure trigle;
var high,base:integer;
begin
     clrscr;
     write('input your base = ');
     readln(base);
     write('inpuut your high = ');
     readln(high);
     clrscr;
     write('area of triangle = ',0.5*base*high:1:2);
     readln;
end;
{MAIN PROGRAM}

begin
  repeat
  clrscr;
  writeln('CALCULATOR PROGRAM');
  writeln;
  writeln;
  writeln('Select one..');
  writeln;
  writeln('1.Multiply Table');
  writeln('2.Plus Calculation');
  writeln('3.Minus Calculation');
  writeln('4.Multiply Calculation');
  writeln('5.Divide Calculation');
  writeln('6.Square Root Calculation');
  writeln('7.Square Calculation');
  writeln('8.Area of circle');
  writeln('9.Area of triangle');
  writeln('0.Exit');
  writeln;
  write(': ');
  writeln;
  writeln;
  writeln;
  writeln('                                       Made by: jittatarn yonsombat M.3/1 No:11');
  gotoxy(3,15);
  readln(menu);
  case menu of
    0:writeln;
    1:table;
    2:plus;
    3:minus;
    4:multi;
    5:divide;
    6:sqt;
    7:sq;
    else writeln;
         writeln('Invalid Choice');
         readln;
  end;
  until menu=0;
  clrscr;
                                       
  readln;
end.
ลองทำออกมาดูเเต่2โปรเเกรมสุดท้ายมัยใช้ไม่ได้อะครับช่วยดูให้หน่อยนะครับ

Moshi

ออฟไลน์
กระทู้ : 16,996
คะแนนขอบคุณ : 45
it4x สังคมแห่งการเรียนรู้
มกราคม 31, 2010, 11:19:46
    0:writeln;
    1:table;
    2:plus;
    3:minus;
    4:multi;
    5:divide;
    6:sqt;
    7:sq;

ตรง Case ก็เพิ่ม 8 , 9 แล้วไปดึง produce มาใช้ เหมือนๆ 0-7 หล่ะัคับ

ผมก็มั่วๆ นะ ฮ่าๆ


 

ด้วยฟังค์ชั่น ตอบด่วน คุณสามารถใช้โค๊ดและ เครื่องหมายแสดงอารมณ์ได้ เหมือนการตั้งกระทู้ธรรมดา แต่สามารถทำได้สะดวกกว่า

ระวัง: หัวข้อนี้ไม่มีการอัพเดทมานานถึง 120 วัน

แจ้งเตือน: โพสของคุณจะไม่แสดงจนกว่าผู้ดูแลจะอนุมัติ.
ชื่อ: อีเมล์: