C programming Assignment Washing Machine System
Short Description
Download C programming Assignment Washing Machine System...
Description
UCTI
(CT018-3-1)
Introduction To C Programming (CT018-3-1)
Cover Page Group Project Instruction:
Complete this cover page (page 1) and attach it to your project – THIS MUST BE YOUR FIRST PAGE in your hard copy documentation.
Group Leader’s Signature:
Date:17/oct/2011
Lecturer : Ms. SEETHA LETCHUMY
Class Code: UC1F1101-IT L1
Submission Date
17/oct/2011
Students Full Name
Leader:Ali Reza Yassi
{TP 025044}
Members: Babak Esparham
{ TP024889}
Hossin Mohamadian far
{ TP024352}
(Indicate Student ID in brackets)
Due Date:
Total number of pages including this cover page.
Washing Machine System
17/oct/2011
40
Page 1
UCTI
(CT018-3-1)
Contents Acknowledgement ............................................................................................................... 4 Introduction ......................................................................................................................... 5 How to Creating C Programs .............................................................................................. 5 Editing ............................................................................................................................. 5 Compiling ........................................................................................................................ 6 Linking............................................................................................................................. 6 Executing ......................................................................................................................... 6 Objective .............................................................................................................................. 7 Case Study ........................................................................................................................... 7 Program Design ................................................................................................................... 9 Program Flowchart whole program ................................................................................. 9 Program Flowchart main menu ..................................................................................... 10 Program Flowchart load capacity .................................................................................. 11 Program Pseudo Code ................................................................................................... 12 Pseudo code for on, off key ............................................................................................... 12 Pseudo code for main menu .............................................................................................. 12 Pseudo code for load capacity menu ................................................................................. 13 Pseudo code for wash menu .............................................................................................. 14 Pseudo code for sock menu ............................................................................................... 15 Pseudo code for time menu ............................................................................................... 16 Pseudo code for temperature menu ................................................................................... 16 Pseudo code for detail menu .............................................................................................. 17 Source Code ................................................................................................................... 17 Source Files ............................................................................................................... 17 Sample Outputs.................................................................................................................. 28 State on and off .............................................................................................................. 28 Washing Machine System
Page 2
UCTI
(CT018-3-1)
Main Menu ................................................................................................................... 29 View Log b .................................................................................................................... 30 Load Capacity Menu ..................................................................................................... 31 Wash Menu .................................................................................................................... 32 Soak or no soak.............................................................................................................. 33 Soak ............................................................................................................................... 34 Soak menu (more than 60 minutes) ............................................................................... 35 Temperature Menu ........................................................................................................ 36 View log ........................................................................................................................ 37 ADDITIONLA FEATURES ............................................................................................. 38 ASSUMPTION .................................................................................................................. 38 Conclusion ......................................................................................................................... 38 References ......................................................................................................................... 39 Workload Matrix ............................................................................................................... 40
Washing Machine System
Page 3
UCTI
(CT018-3-1)
Acknowledgement
We are thankful to our lecture, Ms. SEETHA LETCHUMY who has a major effect on our opinion about C programming. As well for the time and energy made in making sure that we understood the basic and progressive features of C program writing. Also we would like to thanks to our fellow colleagues and home mate who aided us in comprehend and debugging some of the faults which we encountered as well.
Washing Machine System
Page 4
UCTI
(CT018-3-1)
Introduction The C program writing language was established by Dennis Ritchie at AT&T Bell Test center in the first 1970s. It was not till the getting on 1970s, though, that this encoding language created to increase general approval and provision. In this point of view, until that period C compilers were not readily accessible for marketable usage outside of Bell Test center. To begin with, C program language develop in admiration was also stimulated on in share by the equivalent, if not quicker, progress in admiration of the UNIX OS. Talking about operating system, which was also industrialized at Bell Research laboratory, had C as its ―standard‖ program design language. Indeed, more over 90% of the OS‘s it was printed in the C language. C encoding is a very dense language, so there isn‘t a ration of syntax to study beforehand you can code actual submissions. In malice of its succinctness and ease, it‘s also a tremendously influential language that‘s still commonly used by experts. The influence of C program writing is such that it is used for computer programmer at all stages with any level of knowledge, from expedient drivers and operating system components such as small-scale such as we have here in this assignment to large-scale applications.
How to Creating C Programs There are 4 essential platforms in the formation of any C database as we mention here briefly: i.
Editing
ii.
Compiling
iii.
Linking
iv.
Executing
Editing This is the course of creating and adapting C basis code—the name assumed to the database instructions you coding. Certain C compilers introduce with exact editor that can offer a lot of support in handling your programs as well. Indeed, an editor often offers a whole setting for writing, handling, emerging, and testing your codes. This is occasionally named IDE.
Washing Machine System
Page 5
UCTI
(CT018-3-1)
Compiling The compiler translates your basis codes into engine language and notices and reports mistakes in the compilation course. The input to this period is the case you create during your excision, which is usually mentioned to as a basis file as well. The compiler can notice an extensive variety of faults that are due to unacceptable or unrecognized database code, and also mechanical errors where, for instance, some part of a database can never be performed. The output from the compiler is recognized as entity code and is kept in records called object files, which typically have tags with the allowance.
Linking The linker chains the numerous modules produced by the compiler from basis code files, enhances essential code components from program libraries complete as part of C program, and repairs the whole thing into an executable entire. The linker cans similarly notice and report faults, for instance, if part of your database is lost or a missing library constituent is referenced in deed.
Executing The implementation period is where you run your database, having finished all the earlier processes positively. Unfortunately, this period can also make an extensive change of fault situations that can contain making the mistaken output or just inactive and nil, maybe crashing your PC for good amount.
Washing Machine System
Page 6
UCTI
(CT018-3-1)
Objective Generate a scheme to controller a replicated washing machine. On the sour face of the washing machine component are some buttons and also each signified with a letter.
Case Study We are requested to generate a organization to mechanism a simulated washing mashing consuming some buttons in which each button signified with a alphabet acceptable for the washing machine to be well-ordered that operator is to allocate On and Off pin and when the washing machine is switch on using the On and Off key which signified by O letter the operator will has the choice of deciding whether including: i.
(V) View log: if this choice is selected you can be able to understanding the washing machine process logs conferring to the previous worked.
ii.
(W) Wash clothes: if this key is nominated the capacity menu will perform.
When the load capacity perform, the operator will need to control the scope of the weight which include i.
(S)Small,
ii.
(M) medium,
iii.
(L) large,
iv.
(X) extra-large,
v.
(f)free load, In view of that there is a least and last rate for each load capacity as well. Whenever the size of the clothes has been nominated, the wash menu is started and now the operator is given the choices to choice: 1. (F) full wash, 2. (W) wash, 3. (R) rinse, 4. (S) Spain.
Washing Machine System
Page 7
UCTI
(CT018-3-1)
(F) Contain of washing, rinsing and spinning. It moreover contains Sock but contingent on the collection completed in the sock menu which perform when the full wash is started. In the sock menu the user has the choices whether to choice: i.
(N) No soaking and when this has been nominated the program will continue to following menu choice (Temperature menu)
ii.
(S) Sock, the system will move the operator for the total of minutes to sock and the database will continue to the following menu witch is (Temperature menu).
Temperature menu start first after either the (F) or (W) selection has been nominated and the operator will be given the selections whether to choose (H) hot or (C) cold as well. When all the essential inputs have been delivered to the washing machine‘s classification, the program offers the operator with the assessed time of implementation the wash as planned and all these specifics are kept in a view log at all.
Washing Machine System
Page 8
UCTI
(CT018-3-1)
Program Design Program Flowchart whole program START
Main menu
ON View Log
Log
Log Information
Exit Wash
Exit
END
Wash ON
-
Small Medium Large Extra Large Free Load
Wash
NO
Wash
NO
Spin
YES
- Full Wash - Wash
Soak
Rinse
Rinse
Spin
END
END
YES
Time 1-60 minutes
Wash
Hot
Wash
NO
- Hot - Cold
Cold
Wash
End
Washing Machine System
Page 9
UCTI
(CT018-3-1)
Program Flowchart main menu
start
Select from menu
Read selection
wash
no
yes
View log
yes
Display load capacity menu
Display log file
end
Washing Machine System
Page 10
UCTI
(CT018-3-1)
Program Flowchart load capacity
start
Display menu
Select from menu
Read data
small
medium
large
Extra large
Free load
yes
Display KGs
end
Washing Machine System
Page 11
UCTI
(CT018-3-1)
Program Pseudo Code
Pseudo code for on, off key START Show statistics (time and date)
WHILE selection is O or ANY THING ELSE If selection is O Show Machine is on Show Main menu
Else Show machine is off, run the program again
ENDDO
Pseudo code for main menu If selection is O
WHILE selection is O
Washing Machine System
Page 12
UCTI
(CT018-3-1) Show main menu selections Case W Goes to ―wash clothes‘ (Show load capacity menu) Break Case ‗V‘ or ‗v‘ Show ‗view log‖ (Display the kept statistics) Break
ENDDO
Pseudo code for load capacity menu If selection is W
WHILE selection is W
Show main load capacity Case S Print small, the size is between 1-2 kg (Show wash menu) Break Case M Print Medium, the size is between2-3kg (Show wash menu) Break Case L Print Large, the size is between3-4kg (Show wash menu)
Washing Machine System
Page 13
UCTI
(CT018-3-1) Break Case X Print Extra-large, the size is more than 4kg (Show wash menu) Break Case F Print ―Free load, machine determine the load capacity (Display wash menu) Break
ENDDO
Pseudo code for wash menu If choice is: S or M or L or X or F
WHILE selection is: S or M or L or X or F Show wash menu
Item F Print ―full wash (Washing, Rinsing, and Spinning)‖ (Show soak menu) Break Item W Print ―wash‖ (Show soak menu) Break Item ‗R‘ or ‗r‘ Print ―Rinsing‖
Washing Machine System
Page 14
UCTI
(CT018-3-1) (Show Detail menu) Break Item S Print ―Spin‖ (Show Detail menu) Break
ENDDO
Pseudo code for sock menu If the choice is (F) or (W)
WHILE choice is (F) or (W) Show sock menu Item S Print sock (Show time menu) Break
Case N Print No soaking (Show temperature menu) Break ENDDO
Washing Machine System
Page 15
UCTI
(CT018-3-1)
Pseudo code for time menu If the choice is (S) Show time menu Print ―Enter time from (1minute to 60 minutes) If user type more than 60 minutes
Print you type more than 60 minutes please type again (Show temperature menu) Break
Pseudo code for temperature menu WHILE (Time is Come in), or (N is chooses) Show temperature menu Case H Print ―Hot‖ (Show Detail menu) Break
Case C Print ―Cold‖ (Show Detail menu) Break ENDDO
Washing Machine System
Page 16
UCTI
(CT018-3-1)
Pseudo code for detail menu Show the time and date Show load capacity Show wash menu Show sock menu and temperature.
Source Code Source Files #include "stdafx.h" #include # include #include #include void stateOnOff(); void mainmenu(); void Washcolthes(); void WashMenu(); void soak(); void getTimesoak(); void Temperature(); void viewlog(); void viewlogb(); void readviewlogb(); char result[4]; int main(void); int times,count; int _tmain(int argc, _TCHAR* argv[]) { stateOnOff();
Washing Machine System
Page 17
UCTI
(CT018-3-1) return 0;
} int main(void) { time_t timer = time(NULL); printf("current time is %s", ctime(&timer)); stateOnOff(); } void stateOnOff() { system("color 1B"); char ch; printf("\n**************************************************************"); printf("\n*
((wellcome dear user))
*");
printf("\n**************************************************************"); printf("\nPress (o) to washing machine start?"); ch=_getch(); printf("\n%c",ch); if(ch=='o'){ printf("\nWashing machine is On."); mainmenu(); }else printf("\nWashing machine is Off.run the mechine again"); stateOnOff(); } void mainmenu() { system("cls"); char ch; printf("\n**************************************************************"); printf("\n*
((Main Menu))
*");
printf("\n**************************************************************"); printf("\nIf you want to wash clothes,please type w:"); printf("\nIf you want to see view log,please type v :");
Washing Machine System
Page 18
UCTI
(CT018-3-1) ch=_getch(); printf("\n%c",ch); do { if(ch=='w') Washcolthes(); else if(ch=='v') readviewlogb(); printf("\nInvalid answer.type correctly:"); ch=_getch(); printf("\n%c",ch); }while(ch!='w' && ch!='v');
} void readviewlogb() { FILE *fp; int c; fp = fopen("New Text Doucument.doc", "r");
c = getc(fp); while (c!= EOF) { putchar(c); c = getc(fp); } fclose(fp); printf("\n Press any key to continue..."); getch(); system("cls");
Washing Machine System
Page 19
UCTI
(CT018-3-1) mainmenu();
} void Washcolthes(){ system("cls"); char ch; printf("\n**************************************************************"); printf("\n*
((Size menu))
*");
printf("\n**************************************************************"); printf("\nPlease select size of the your clothes:"); printf("\nEnter s(small) if your cloths between 1-2kgr:"); printf("\nEnter m(medium) if your cloths between 2-3kgr:"); printf("\nEnter l(large) if your cloths between 3-4kgr:"); printf("\nEnter x(Eatra large) if your cloths more than 4kgr:"); printf("\nEnter f(Free load) if machine determines the load capacity:"); ch=_getch(); printf("\n%c",ch); while(ch!='s'&& ch!='m'&& ch!='l' && ch!='x'&& ch!='f'){ printf("\nInvalid answer.type correctly:"); ch=_getch(); printf("\n%c",ch); } result[count]=ch; count++; WashMenu();
} void WashMenu(){ system("cls"); char ch; printf("\n**************************************************************"); printf("\n*
Washing Machine System
((Wash menu))
*");
Page 20
UCTI
(CT018-3-1) printf("\n**************************************************************"); printf("\nPlease select one of the wash menu options for your clothes:"); printf("\nEnterf(full wash)consist of washing ,rinsing and spinning:"); printf("\nEnter w(wash) consist of only washing without rinsing or spinning:"); printf("\nEnter r(rinse)consist of only rinsing without washing or spinning:"); printf("\nEnter s(spin)consist of only spinning without washing or rinsing :"); ch=_getch(); printf("\n%c",ch); while(ch!='f' && ch!='w'&& ch!='r' && ch!='s'){ printf("\nInvalid answer.type correctly:"); ch=_getch(); printf("\n%c",ch); } result[count]=ch; count++; if(ch=='f' || ch=='w'){ soak(); } else{Temperature(); }
} void soak(){ system("cls"); char ch; printf("\n**************************************************************"); printf("\n*
((Soak menu))
*");
printf("\n**************************************************************"); printf("\nIf you want soak please press (y):"); ch=_getch(); printf("\n%c",ch); while(ch!='y' && ch!='n'){
Washing Machine System
Page 21
UCTI
(CT018-3-1) printf("\nInvalid answer.type correctly:"); ch=_getch(); printf("\n%c",ch); } if(ch=='y'){
result[count]=ch; count++; getTimesoak(); } Temperature(); } void getTimesoak(){ system("cls"); int ch; printf("\n**************************************************************"); printf("\n*
((Soak time))
*");
printf("\n**************************************************************"); printf("\nPlease enter time between 1-60 minutes"); scanf_s("%d",&ch); if(ch>60){ printf("\n**************************************************************"); printf("\n*
((warning))
*");
printf("\n**************************************************************"); printf("\nThis time is more than 60 minutes.enter time less than 60 minutes"); scanf_s("%d",&ch); } times =ch; } void Temperature(){ system("cls"); char ch;
Washing Machine System
Page 22
UCTI
(CT018-3-1)
printf("\n**************************************************************"); printf("\n*
((Temperature menu))
*");
printf("\n**************************************************************"); printf("\nEnter h(hot) if you want hot water for operation"); printf("\nEnter c(cold) if you want cold water for operation"); ch=_getch(); printf("\n%c",ch); while(ch!='h' &&ch!='c'){ printf("\nInvalid answer.type correctly:"); ch=_getch(); printf("\n%c",ch); } result[count]=ch; viewlog();
} void viewlog() { system("cls"); printf("\n********************((the machine start to work))********************:"); printf("\n"); int j=0; if(result[j]=='s'){ printf("\nSmall"); }else if(result[j]=='m'){ printf("\nMedium"); }else if(result[j]=='l'){ printf("\nLarge"); }else if(result[j]=='x'){
Washing Machine System
Page 23
UCTI
(CT018-3-1) printf("\nE-xtralarge"); }else if(result[j]=='f'){ printf("\nFreeload"); } //size j++; if(result[j]=='f'){ printf("\nfullwash"); }else if(result[j]=='w'){ printf("\nwash"); }else if(result[j]=='r'){ printf("\nrinse"); }else if(result[j]=='s'){ printf("\nspine"); } ////wash j++; if(result[j]=='y'){ printf(",soak is active"); printf("\nTime for washing your clothes :60 min and for soaking:"); printf("%d",times); printf("\nTotal:"); times+=60; printf("%d",times); printf("min"); } else{
Washing Machine System
Page 24
UCTI
(CT018-3-1) printf("\nSoak isnot active"); printf("\nTime for washing your clothes is :60 minute"); } ////soak j++; if(result[j]=='h'){ printf("\nTemperature water is hot"); }else if(result[j]=='c') {printf("\nTemperature water is cold");} system("pause"); viewlogb(); }
void viewlogb() { system("cls"); FILE *fp; fp = fopen("New Text Doucument.doc","a"); time_t timer = time(NULL); fprintf(fp,"current time is %s", ctime(&timer)); int i=0; if(result[i]=='s'){ fprintf(fp,"%s","Small\n"); }else if(result[i]=='m'){ fprintf(fp,"%s","Medium\n"); }else if(result[i]=='l'){
fprintf(fp,"%s","Large\n"); }else if(result[i]=='x'){
Washing Machine System
Page 25
UCTI
(CT018-3-1) fprintf(fp,"%s","E_xtralarge\n"); }else if(result[i]=='f'){ fprintf(fp,"%s","Freeload\n"); } //size i++; if(result[i]=='f'){ fprintf(fp,"%s","fullwash\n"); }else if(result[i]=='w'){ fprintf(fp,"%s","wash\n"); }else if(result[i]=='r'){ fprintf(fp,"%s","rinse\n"); }else if(result[i]=='s'){
fprintf(fp,"%s","spine\n"); } ////wash i++; if(result[i]=='y'){ fprintf(fp,"%s","soak is active\n"); fprintf(fp,"%s","Time for washing your clothes :60 minute and for soaking:\n"); //printf("%d",time); fprintf(fp,"%d",times); fprintf(fp,"%s","Total\n"); times+=60; fprintf(fp,"%d",times); fprintf(fp,"%s","min");
Washing Machine System
Page 26
UCTI
(CT018-3-1) } else{ fprintf(fp,"%s","soak is not active\n"); fprintf(fp,"%s","Time for washing your clothes is:60 minute:\n"); }
////soak i++; if(result[i]=='h'){ fprintf(fp,"%s","Temperature water is hot\n"); }else if(result[i]=='c') fprintf(fp,"%s","Temperature water is cold\n"); fclose(fp); //done! stateOnOff(); }
Washing Machine System
Page 27
UCTI
(CT018-3-1)
Sample Outputs State on and off
The overhead screen shot displays the current time and date as well as state on and off in the system. Here the operator is supposed to choice whether to on the washing machine . The operator can even see the operation time and date as shown above. Whenever operator types any word instead of O the machine would be off and ask to press O again.
Washing Machine System
Page 28
UCTI
(CT018-3-1) Main Menu
After the user processed to the main menu, then the washing machine gives user two option witch is : W is for wash clothes and V for view the log.
Washing Machine System
Page 29
UCTI
(CT018-3-1) View Log b
After choosing view log the user can view the last process, meaning that the operator can realize all the process that have been done, what kind of action and user can see the date and time that process has done.by pressing any key user can access again to the main menu.
Washing Machine System
Page 30
UCTI
(CT018-3-1) Load Capacity Menu
As a result, after the user selected to the Wash Clothes then the user have to choice the size of the Load Capacity Menu as well, which could contain any one of the next five decisions. The choices including: Small, Medium, Large, Extra-large as well as Free Load. If the operator is not assured on which size to choice has the option to choose Free Load. This means that the operator would be contingent on the machine to control the Load Capacity grounded on the heaviness of the clothes. The weight of the wears can be an accidental generated rate but its value has to be a rational heaviness for clothes put into a machine as well. When the weight is resolute then the Load Capacity is established mechanically to Small, Medium, Large as well as Extra Large. Mention that there should be a least and full rate for each Load Capacity sort. For this situation: 1. Small is less than 2kg, 2. Medium is (2 - 4) kg, 3. Larger is (4 - 6) kg, 4. Extra-large is (6 - 8) kg.
Washing Machine System
Page 31
UCTI
(CT018-3-1)
Wash Menu
Here After the size of the load has been noticed, the Wash Menu is triggered. Then the user now gets to choice from one of the subsequent Wash Menu choices as shown overhead.
Washing Machine System
Page 32
UCTI
(CT018-3-1) Soak or no soak
If the operator choice Full Wash would contain of Washing, Rinsing and Spinning but may contain Soak contingent on the collection made in the Soak Menu which show off when the Full Wash is triggered. Wash would contain of just washing, lacking rinsing or spinning. Though, it may contain Soak contingent on the collection made by the operator from the Soak Menu which show off when Wash is started. In the Soak Menu the operator has the choice to select Soak or Not Soak as well.
Washing Machine System
Page 33
UCTI
(CT018-3-1) Soak
Whenever the operator chooses N, the program will continue to the following menu choice witch is Temperature Menu. If the chooses S, the system will ready the operator for the amount of minutes to soak the clothes. The operator can chose in any rate between 1 – 60 minutes as well. Once the number of minutes is mentioned the program will continue to the following menu choice – Temperature Menu.
Washing Machine System
Page 34
UCTI
(CT018-3-1) Soak menu (more than 60 minutes)
Whenever user type more than 60 minutes the program will show the warning witch is: this time is more than 60 minutes.so user should mention the time less than 60 minutes.
Washing Machine System
Page 35
UCTI
(CT018-3-1) Temperature Menu
This menu is started only after both the Full Wash and the Wash select has been designated. The Temperature Menu holds Hot and Cold as shown overhead. Then if the operator chooses ―H‖, hot water will be recycled for all processes from soaking to rinsing. Or other cold water will be recycled as well.
Washing Machine System
Page 36
UCTI
(CT018-3-1) View log
This menu started after machine got all the information‘s and start to work.as you can see it gives all statistics that the user gave to the machine in the screen.
Washing Machine System
Page 37
UCTI
(CT018-3-1)
ADDITIONLA FEATURES It shows the logs single by single in log view which styles it more contented for operator. In addition, in our program for making chance rate we took the input for the showing in the view log of the screen as well as showing in view log b.
ASSUMPTION We were not given exact way for just out put the information in view log b that the user cannot see that what information he or she given to machine .we create the view log that user can see witch parts of options he or she took. In additional, if user types any wrong type the system would give him or her notification that this answer is in valid. Type again correctly.
Conclusion C is perfect programming languages that can make software design a lot of challenges. Programming in C is a talent that could finish up saving you your occupation or aid you get a healthier occupation. Now in this task the notion was to create a washing machine system by C under convinced restraints stated by the lecturer. Done all this assignment we have been fronting many problems due to our lack of information, but our determination aided us to stare forward, and apply a problematic resolving set of mind. Analysis books, considering in net, requesting from friends were all conducts that we used to exceed the problems.
Washing Machine System
Page 38
UCTI
(CT018-3-1)
References
H.M. Deitel, 2004, How To Program, 4th Edition, United State of American
MATEO, Apprenez à programmer en C, Available from http://www.siteduzero.com/ [Accessed 12 July 2010] EBRAHIM MOHAMADI ,easy c programing, 8th edition,IRAN
Perry G., 1997, C By Example, 6th Edition, United States of America, Prentice Hall. G. Kochan. Stephen, Programming in C,3rd edition, India
Washing Machine System
Page 39
UCTI
(CT018-3-1)
Workload Matrix
Student’s Name
Ali Reza Yassi ---------------------A
Babak Esparham -----------------------B
50% 60% 50% 50% 100% 50%
25% 20% 25% 25% 100% 25%
Tasks Research book Coding Document Net research Group meeting design
Hossin Mohamadin far -----------------------C 25% 20% 25% 25% 100% 25%
Signature of each member Total of 100% I, hereby agree that the above members have undertaken the above tasks and their work is reflected as shown above. Name of Group Leader: Group Leader’s Signature: ____________________
Washing Machine System
Page 40
View more...
Comments