Upcoming SlideShare
×

# Test 1 skema q&a

917 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
917
On SlideShare
0
From Embeds
0
Number of Embeds
264
Actions
Shares
0
46
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Test 1 skema q&a

1. 1. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING TEST 1-MONDAY Write a program to calculate mass of the liquid in a tank. Allow the user to input the volume either in cm or meter, and prompt the user to recalculate if desire. Note that: Oil density (ρ)= 850 kg/m3 Mass=ρVThe output should be similar to:
2. 2. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#include<stdio.h>#include<conio.h>#include<math.h>main(){ float oildensity, tankvolume,mass=0; char oilunit,again; printf("This program calculate the mass of oil in a tank"); start: printf("nnEnter oil density: ");scanf("%f",&oildensity); printf("Enter tank volume: ");scanf("%f",&tankvolume); printf("nEnter volume unit(m=meter, c=centimeter): ");scanf("%s",&oilunit); recalculate: switch (oilunit){ case c: mass= oildensity*((pow(tankvolume,3))/pow(100,3)); break; case m: mass= oildensity*(pow(tankvolume,3)); break; default: printf("You have entered a wrong type of unit"); printf("nnEnter oil density unit(g for gram/k for kg): ");scanf("%s",&oilunit); goto recalculate; } printf("nntThe Mass of oil is %.4fkg",mass); printf("nnDo you want to re-calculate: ");scanf("%s",&again); if(again==y || again==Y) goto start; getch(); }
3. 3. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#include<stdio.h>#include<conio.h>#include<math.h>main(){ float oildensity, tankvolume,mass=0; char oilunit,again; printf("This program calculate the mass of oil in a tank"); start: printf("nnEnter oil density: ");scanf("%f",&oildensity); printf("Enter tank volume: ");scanf("%f",&tankvolume); printf("nEnter volume unit(m=meter, c=centimeter): ");scanf("%s",&oilunit); recalculate: if (oilunit== c){ mass= oildensity*((pow(tankvolume,3))/pow(100,3)); } else if (oilunit== m){ mass= oildensity*(pow(tankvolume,3));} else{ printf("You have entered a wrong type of unit"); printf("nnEnter oil density unit(g for gram/k for kg): ");scanf("%s",&oilunit); goto recalculate; } printf("nntThe Mass of oil is %.4fkg",mass); printf("nnDo you want to re-calculate(enter y for yes): ");scanf("%s",&again); if(again==y || again==Y) goto start; getch(); }
4. 4. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#include<stdio.h>#include<conio.h>main(){ float oildensity, tankvolume,mass=0; char oilunit,again; printf("This program calculate the mass of oil in a tank"); start: printf("nnEnter oil density: ");scanf("%f",&oildensity); printf("Enter tank volume: ");scanf("%f",&tankvolume); printf("nEnter volume unit(m=meter, c=centimeter): ");scanf("%s",&oilunit); recalculate: switch (oilunit){ case c: mass= oildensity*(tankvolume/100); break; case m: mass= oildensity*tankvolume; break; default: printf("You have entered a wrong type of unit"); printf("nnEnter oil density unit(g for gram/k for kg): ");scanf("%s",&oilunit); goto recalculate; } printf("nntThe Mass of oil is %.4fkg",mass); printf("nnDo you want to re-calculate: ");scanf("%s",&again); if(again==y || again==Y) goto start; getch(); }
5. 5. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#include<stdio.h>#include<conio.h>main(){ float oildensity, tankvolume,mass=0; char oilunit,again; printf("This program calculate the mass of oil in a tank"); start: printf("nnEnter oil density: ");scanf("%f",&oildensity); printf("Enter tank volume: ");scanf("%f",&tankvolume); printf("nEnter volume unit(m=meter, c=centimeter): ");scanf("%s",&oilunit); recalculate: if (oilunit== c){ mass= oildensity*(tankvolume/100); } else if (oilunit== m){ mass= oildensity*tankvolume;} else{ printf("You have entered a wrong type of unit"); printf("nnEnter oil density unit(g for gram/k for kg): ");scanf("%s",&oilunit); goto recalculate; } printf("nntThe Mass of oil is %.4fkg",mass); printf("nnDo you want to re-calculate(enter y for yes): ");scanf("%s",&again); if(again==y || again==Y) goto start; getch(); }
6. 6. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING TEST 1-TUESDAY Base on the table develop a simple program on how long should a man/woman should exercise to burn calories off either by jogging or bicycling. The user must be able to keep calculating until the key end otherwise. Example: A 65kg woman needs to burn of 800 calories by jogging, how long does she need to jog in order to burn of all of the calories. 540 Energy output: ℎ Δ 64 x 68 68 800 Duration: Δ 516.17The output should be similar to :
7. 7. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#includestdio.h#includeconio.hmain(){ float calorin,weight,totalhour=0; int type; char again; printf(ttt444Exercise Calculator444nn); start: printf(nEnter calories intake: );scanf(%f,calorin); printf(Enter your weight: );scanf(%f,weight); choose: printf(nPlease choose type of exercise n1. Joggingn2. BicyclingnPlease enter type:);scanf(%d,type); switch(type){ case 1: totalhour=calorin/(weight*(540/68)); printf(ntIn order to burn %.f of calories you need to jog for%.1fhr,calorin,totalhour);break; case 2: totalhour=calorin/(weight*(639/68)); printf(ntIn order to burn %.f of calories you need to cycle for%.1fhr,calorin,totalhour);break; default: goto choose;break; } if(again==y || again==Y) goto start; getch(); }
8. 8. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#includestdio.h#includeconio.hmain(){ float calorin,weight,totalhour=0; int type; char again; printf(ttt444Exercise Calculator444nn); start: printf(nEnter calories intake: );scanf(%f,calorin); printf(Enter your weight: );scanf(%f,weight); choose: printf(nPlease choose type of exercise n1. Joggingn2. BicyclingnPlease enter type:);scanf(%d,type);if (type==1){totalhour=calorin/(weight*(540/68));printf(ntIn order to burn %.f of calories you need to jog for %.1fhr,calorin,totalhour); }else if (type==2){totalhour=calorin/(weight*(639/68));printf(ntIn order to burn %.f of calories you need to cycle for %.1fhr,calorin,totalhour); }else { goto choose;} if(again==y || again==Y) goto start; getch(); }
9. 9. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING TEST 1-TUESDAY Base on the table develop a simple program on how long should a man/woman should exercise to burn calories off either by jogging or playing tennis. The user must be able to keep calculating until the key end otherwise. Example: A 65kg woman needs to burn of 800 calories by jogging, how long does she need to jog in order to burn of all of the calories. 540 Energy output: ℎ Δ 64 x 68 68 800 Duration: Δ 508.23The output should be similar to :
10. 10. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#includestdio.h#includeconio.hmain(){ float calorin,weight,totalhour=0; int type; char again; printf(ttt444Exercise Calculator444nn); start: printf(nEnter calories intake: );scanf(%f,calorin); printf(Enter your weight: );scanf(%f,weight); choose: printf(nPlease choose type of exercise n1. Joggingn2. TennisnPlease enter type:);scanf(%d,type); switch(type){case 1:totalhour=calorin/(weight*(540/68));printf(ntIn order to burn %.f of calories you need to jog for %.1fhr,calorin,totalhour);break;case 2:totalhour=calorin/(weight*(480/68)); printf(ntIn order to burn %.f of calories you need to play intense tennis for %.1fhr,calorin,totalhour); break;default:goto choose; break; } printf(nnDo you want to re-calculate(enter y for yes): );scanf(%s,again); if(again==y || again==Y) goto start; getch(); }
11. 11. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#includestdio.h#includeconio.hmain(){ float calorin,weight,totalhour=0; int type; char again; printf(ttt444Exercise Calculator444nn); start: printf(nEnter calories intake: );scanf(%f,calorin); printf(Enter your weight: );scanf(%f,weight); choose: printf(nPlease choose type of exercise n1. Joggingn2. TennisnPlease enter type:);scanf(%d,type);if(type==1){totalhour=calorin/(weight*(540/68));printf(ntIn order to burn %.f of calories you need to jog for %.1fhr,calorin,totalhour);}else if(type==2){totalhour=calorin/(weight*(480/68));printf(ntIn order to burn %.f of calories you need to play intense tennis for%.1fhr,calorin,totalhour); }else{goto choose; } printf(nnDo you want to re-calculate(enter y for yes): );scanf(%s,again); if(again==y || again==Y) goto start; getch(); }
12. 12. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING TEST 1-TUESDAY Base on the table develop a simple program on how long should a man/woman should exercise to burn calories off either by fast swimming or bicycling. The user must be able to keep calculating until the key end otherwise. Example: A 65kg woman needs to burn of 800 calories by jogging, how long does she need to jog in order to burn of all of the calories. 540 Energy output: ℎ Δ 64 x 68 68 800 Duration: Δ 508.23The output should be similar to :
13. 13. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#includestdio.h#includeconio.hmain(){ float calorin,weight,totalhour=0; int type; char again; printf(ttt444Exercise Calculator444nn); start: printf(nEnter calories intake: );scanf(%f,calorin); printf(Enter your weight: );scanf(%f,weight); choose: printf(nPlease choose type of exercise n1. Fast Swimmingn2. BicyclingnPlease enter type:);scanf(%d,type); switch(type){ case 1: totalhour=calorin/(weight*(860/68)); printf(ntIn order to burn %.f of calories you need to fast swimming for%.1fhr,calorin,totalhour);break; case 2: totalhour=calorin/(weight*(639/68)); printf(ntIn order to burn %.f of calories you need to cycle for%.1fhr,calorin,totalhour); break; default: goto choose;break; }
14. 14. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#includestdio.h#includeconio.hmain(){ float calorin,weight,totalhour=0; int type; char again; printf(ttt444Exercise Calculator444nn); start: printf(nEnter calories intake: );scanf(%f,calorin); printf(Enter your weight: );scanf(%f,weight); choose: printf(nPlease choose type of exercise n1. Fast Swimmingn2. BicyclingnPlease enter type:);scanf(%d,type);if(type==1){totalhour=calorin/(weight*(860/68));printf(ntIn order to burn %.f of calories you need to fast swimming for %.1fhr,calorin,totalhour);}else if (type==2){totalhour=calorin/(weight*(639/68));printf(ntIn order to burn %.f of calories you need to cycle for %.1fhr,calorin,totalhour); }else{ goto choose; } if(again==y || again==Y) goto start; getch(); }
15. 15. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING TEST 1-WEDNESDAY Develop a simple program to calculate radius of a circle. The user need to choose whether to input area or circumference of the circle. Note that: area= πxrad2 and circumference = 2xπxradThe output should be similar to:The user must be able to keep calculating until the key end otherwise.
16. 16. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#includestdio.h#includeconio.h#includemath.h#define PI 3.1416main(){ char type,again; float radius,circumference,area; printf(t444This program calculate radius of a circle444); start: printf(nna:areanc:circumferencennEnter the information that you have:); scanf(%s,type); cal: switch(type){ case a: printf(nEnter area of a circle:);scanf(%f,area); radius = sqrt(area/PI); printf(nThe area of a circle is %.2f while the radius is %.4f,area,radius); break; case c: printf(nEnter circumference of a circle:);scanf(%f,circumference); radius= circumference/(PI*2); printf(nThe circumference of a circle is %.2f while the radius is %.4f,circumference,radius);break; default: printf(na:areanc:circumferencennPlease re-enter selection:); scanf(%s,type); goto cal; } if(again==y || again==Y) { goto start;} getch(); }
17. 17. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING#includestdio.h#includeconio.h#includemath.h#define PI 3.1416main(){ char type,again; float radius,circumference,area; printf(t444This program calculate radius of a circle444); start: printf(nna:areanc:circumferencennEnter the information that you have:); scanf(%s,type); cal: if (type==a){ printf(nEnter area of a circle:);scanf(%f,area); radius = sqrt(area/PI); printf(nThe area of a circle is %.2f while the radius is %.4f,area,radius);} else if(type== c){ printf(nEnter circumference of a circle:);scanf(%f,circumference); radius=circumference/(PI*2);printf(nThe circumference of a circle is %.2f while the radius is %.4f,circumference,radius);} else{ printf(na:areanc:circumferencennPlease re-enter selection:); scanf(%s,type); goto cal;} if(again==y || again==Y) goto start; getch(); }
18. 18. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING TEST 1-WEDNESDAY Develop a simple program to calculate either an area or perimeters of a semi circle. The program must prompt the user to input radius. Note that: area= πxrad2 and circumference = 2xπxradThe output should be similar to : 20.7075The user must be able to keep calculating until the key end otherwise.