Vous êtes sur la page 1sur 11

2011

Name: MOHD FARID FAUZI

[PROGRAMMING FOR ENGINEERS]


A program to help the user to determine the displacement and acceleration at certain time from a given data.

CONTENTS
1. OBJECTIVE 2. ALGORITHM 3. FLOWCHART 4. PSEUDOCODES 5. SOURCE CODE 6. CONCLUTION 7. REFERENCE 2 2 3-5 6 7-9 10 10

Page

OBJECTIVE
The objective of this report is to provide a program C to help the user determine the displacement and acceleration at certain time period based from a given data of time and velocity of an object and also includes the flow chart of the program.

ALGORITHM
1. The displacement of the object at stated/certain time period. v = u + at s = ut + at2 s = v0t + = = = = = = = (v1 -v0) 2 t t v0t + (v1 -v0) t vt vt v0t + 1 - 0 2 2 v0t v1t + 2 2 (v0t + v1t) (v0 + v1 ) t (v0 + v1 ) (t1-t0) (v0 + v1 ) (t1-t0) + s0 Computer form

s1-s0 s1

Sf = 0.5*(Tf-Ti)*(Vi+Vf)+Si 2. The average acceleration at that time v = u + at at = v - u at = v1 v0 (v1 -v0) a = t (v1 -v0) a = (t1-t0) Ac=(Vf-Vi)/(Tf-Ti)

Computer form

Page

FLOWCHARTS
START

DISPLAY MAIN MENU

USER INPUT: MENU_SELECT 1,2,3,4,5

option1
DISPLAY GIVEN DATA FILE

option2
FIND THE DISPLACEMENT ACCELERATION

option3
SAVED DATA TO FILE

option4
ABOUT ME

option5
EXIT

NO
USER_INPUT

== '5'

YES

END

Page

OPTION 1
OPTION1

READ DATA FROM FILE

DISPLAY READ DATA FROM FILE

RETURN

OPTION 2
OPTION2

ENTER FILENAME

READ DATA FROM FILE Sf=0.5*(Tf-Ti)*(Vi+Vf)+Si; Ac=(Vf-Vi)/(Tf-Ti);

DISPLAY DISPLACEMENT AND ACCELERATION

Page

RETURN

OPTION 3
OPTION3

ENTER FILENAME

READ DATA FROM FILE

Sf=0.5*(Tf-Ti)*(Vi+Vf)+Si; Ac=(Vf-Vi)/(Tf-Ti);

SAVED DISPLACEMENT AND ACCELERATION

RETURN

OPTION 4

OPTION4

DISPLAY ABOUT ME

RETURN

Page

PSEUDOCODES
1. Start main Start looping {Display menu Select option y option1,option2,option3,option4,option5 }end looping 2. if option1 open data file motion.dat read data from file print it to command prompt(cmd) clear screen close data file return to main 3. if option2 open data file motion.dat read data from file process and formula print it to command prompt(cmd) clear screen close data file motion.dat return to main 4. if option3 open data file motion.dat ask to enter filename open data to write/save read data from file process and formula print it to file(to save) clear screen close data file motion.dat close data file filename return to main 5. if option4 display programmer profile return to main 6. if option5 exit

Page

SOURCE CODE
#include<stdio.h>//library call #include<stdlib.h>// for atof and system used void option1()//display function { int i; char kod[4],kod3[4],kod2[4]; FILE *mama; mama=fopen("motion.dat","r");//open file motion.dat for(i=0;i<=1;i++) { printf("\n"); fscanf(mama,"%s %s\n",kod,kod2);//read from file printf("%s\t%s",kod,kod2); }printf("\r");system("PAUSE"); system("CLS");//clear sreen fclose(mama); } void option2()//displacement n acceleration function { int i; char kod[4],kod3[4],kod2[4]; double Si,Sf,Vi,Vf,Ac,Tf,Ti; Si=Sf=Vi=Vf=Ac=Tf=Ti=0; FILE *mama; mama=fopen("motion.dat","r");//open file motion.dat fscanf(mama,"%s %s\n",kod,kod2);//read 1st line... fscanf(mama,"%s %s\n",kod,kod2);//read second line printf(" t\t s\t a\n"); Vi=atof(kod2);//changing from string to double Ti=atof(kod); printf("%.2f\t%.2f\t%5.2f",Ti,0,0); for(i=0;i<=1;i++) { printf("\n"); fscanf(mama,"%s %s\n",kod,kod2);//read data from file Vf=atof(kod2); Tf=atof(kod); Sf=0.5*(Tf-Ti)*(Vi+Vf)+Si;//displacement formula Ac=(Vf-Vi)/(Tf-Ti);//Acceleration formula printf("%.2f\t%.2f\t%5.2f",Tf,Sf,Ac);//print data to cmd Vi=atof(kod2); Ti=atof(kod);

Page

}printf("\r");system("PAUSE");system("CLS"); fclose(mama);//close file motion.dat

void option3()//saved to file function { int i; char kod[4],kod3[4],kod2[4],filename[20]; double Si,Sf,Vi,Vf,Ac,Tf,Ti; Si=Sf=Vi=Vf=Ac=Tf=Ti=0; FILE *mama; mama=fopen("motion.dat","r");//open file to read printf("Please insert filename to save. Including extension.(example: ANSWER.txt)\n"); scanf("%s",&filename);//Name of the file to be saved FILE *papa; papa=fopen(filename,"w");//open file to write on(to save) fscanf(mama,"%s %s\n",kod,kod2); fscanf(mama,"%s %s\n",kod,kod2);//scan dta from file(2nd line) fprintf(papa," t\t s\t a\n");//print data to selected file Vi=atof(kod2); Ti=atof(kod); fprintf(papa,"%.2f\t%.2f\t%5.2f",Ti,0,0); for(i=0;i<=1;i++) { fprintf(papa,"\n"); fscanf(mama,"%s %s\n",kod,kod2); Vf=atof(kod2); Tf=atof(kod); Sf=0.5*(Tf-Ti)*(Vi+Vf)+Si; Ac=(Vf-Vi)/(Tf-Ti); fprintf(papa,"%.2f\t%.2f\t%5.2f",Tf,Sf,Ac); Vi=atof(kod2); Ti=atof(kod); } fclose(mama);//close reading file fclose(papa);//close writing file(saved data) printf("File being saved...\n\nOpen cpp directory to read it\n"); printf("File can be opened using notepad..\n\n"); system("PAUSE");system("CLS"); } void option4() { //personal info printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<"); printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> about me <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<"); printf(">>> FACULTY OF MECHANICAL ENGINEERING,UNIVERSITI TEKNOLOGI MALAYSIA SKUDAI <<<"); printf(">>> RAZMAN MURAD <<<");//name

Page

printf(">>> SX101183 MMJ03 <<<"); printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<"); system("PAUSE");system("CLS"); } void main() { for(;;)//looping it till you want to end it { char select; // User Interface 4 this program printf("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\ n"); printf("::::^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^::::\ n"); printf(":::: PROGRAM TO CALCULATE DISPLACEMENT & ACCELERATION ::::\n"); printf("::::>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<::::\ n"); printf(":::: 1. Display data on file. ::::\n"); printf(":::: 2. Calculate displacement and acceleration. ::::\n"); printf(":::: 3. Save data to file. ::::\n"); printf(":::: 4. About me. ::::\n"); printf(":::: 5. Exit. ::::\n"); printf(":::: ::::\n"); printf(":::::: PLEASE ENTER A CHOICE TO PROCEED ::::::___:::::::::::"); printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");//backspace scanf("%s",&select); printf("\n\n\n"); switch(select) { case '1' : option1();//function call break; case '2' : option2();//function call break; case '3' : option3();//function call break; case '4' : option4();//function call break; case '5' : printf("Program is exiting....\n\n"); break; default : printf("Access denied..\nSorry you enter the wrong input..\n"); system("PAUSE");system("CLS"); break; }if (select=='5') break; } }

Page

CONCLUSION

After finished this report, I learn how to create and understand the programming fundamentals such as by creating algorithm, flowchart and then the program itself using various type of variables, Operators, statements, and expressions.

REFERENCES
1. www.fkm.com/mohamed/ 2. BYRON S. GOTTFRIED, PH.D. SCHAUMS OUTLINES OF PROGRAMMING WITH C SECOND EDITION McGRAW-HILL 1996

11

Page

10

Vous aimerez peut-être aussi