computer programming
DESCRIPTION
CBCP2103 September 2012TRANSCRIPT
SEPTEMBER SEMESTER 2012
CBCP2103
COMPUTER PROGRAMMING
TUTOR: YUZERY BIN YUSOFF
MATRICULATION NO : R336825001
IDENTITY CARD NO. : A1031320
TELEPHONE NO. : 012-2856722
E-MAIL : [email protected]
LEARNING CENTRE : BANGI
CBCP2103
TABLE OF CONTENT page
1.0 Question 1 (Bills for the City Water Company)…………………………………….2
1.1 Coding for Question 1………………………………………………………..2
1.2 Screenshots for Question 1…………………………………………………..5
1.3 Flowchart for Question 1………………………………………………….....9
2.0 Question 2 (Table of Engineering
Properties for Bunyan Lumber Company)………………………………………….10
2.1 Coding for Question 2……………………………………………………….10
2.2 Screenshots for Question 2………………………………………………….12
2.3 Flowchart for Question 2…………………………………………………....13
References……………………………………………………………………………….14
1
CBCP21031.0 Question 1 (Bills for the City Water Company)
1.1 Coding for Question 1
/* CBCP2103 Computer Programming Assignment : Question 1 */
/* Name: Dewa Putu Teja Laksana */
/* Matric No.: R336825001 */
/* Semester: September 2012 */
#include <stdio.h> /* Defining Standard Input and Output routines */
/* ------------------------------------ */
/* Function for Bill Amount */
/* ------------------------------------ */
int main()
{
printf("\nWATER COMPANY BILLING SYSTEM\n"); /* Heading of the system */
printf("=============================\n\n");
int accountNo;
char codeType;
double waterAmount;
float bill;
printf("Please enter your account no: "); /* Enter user's account number */
scanf("%d", &accountNo);
2
CBCP2103 printf("\ncode type usage");
printf("\n---------------\n");
printf("h = home use \nc = commercial use \ni = industry use\n");
printf("\nPlease enter your code type (h/c/i): "); /* Enter usage code of the user */
scanf("\n%c", &codeType);
printf("Now enter water amount (gallons): "); /* Enter the quantity of water used */
scanf("%lf", &waterAmount);
/* Calculation of the bill according to the code type */
switch (codeType) {
case ('h'): bill = 5.00 + (0.0005 * waterAmount);
break;
case ('c'): if (waterAmount <= 4000000)
bill = 1000.00;
else if (waterAmount > 4000000)
bill = (((waterAmount - 4000000) * 0.00025) + 1000);
break;
case ('i'): if (waterAmount <= 4000000)
bill = 1000;
else if ((waterAmount >= 4000000) && (waterAmount <= 10000000))
bill = 2000;
else
bill = 3000;
3
CBCP2103 break;
default : printf("\nYou enter wrong code!!\n\n"); /* If the code type other than h or c or i */
}
printf("bill = %lf\n", bill);
printf("=============================\n\n");
printf("You need to pay: RM %.2lf", bill);
getch();
return 0;
}
4
CBCP2103
1.2 Screenshots for Question 1
Picture 1.2.1. Screenshot for displaying bill of home type usage.
Picture 1.2.2. Screenshot for displaying bill of commercial type usage for the first 4 million gallons used.
5
CBCP2103
Picture 1.2.3. Screenshot for displaying bill of commercial type usage with water quantity exceeds 4 million gallons.
Picture 1.2.4. Screenshot for displaying bill of industry type usage with water quantity does not exceed 4 million gallons.
6
CBCP2103
Picture 1.2.5. Screenshot for displaying bill of industry type usage with water used is more than 4 million gallons but does not exceed 10 million gallons.
Picture 1.2.6. Screenshot for displaying bill of industry type usage with water used is more than 10 million gallons.
7
CBCP2103
Picture 1.2.7. Screenshot for displaying when user input code type other than h / c /i.
8
CBCP2103
1.3 Flowchart for Question 1
9
CBCP2103
2.0 Question 2 (Table of the Engineering Properties for Bunyan Lumber Company).
10
CBCP21032.1 Coding for Question 2
/* CBCP2103 Computer Programming Assignment : Question 2 */
/* Name: Dewa Putu Teja Laksana */
/* Matric No.: R336825001 */
/* Semester: September 2012 */
/* This program creates value of Engineering Properties of Lumber */
#include <stdio.h> /* Defining Standard Input Output routines */
/* -------------------------------- */
/* Function for the table of value */
/* -------------------------------- */
int main()
{
printf("\n\t\t\tBUNYAN LUMBER COMPANY\n"); /* Heading for the system */
printf("\n\t\t Engineering Properties of Lumber\n");
printf("\t\t====================================\n\n");
printf("\n");
printf("Lumber Size(Inch) | Cross-Sectional | Moment of Inertia | Section Modulus |"); /* Engineering properties */
printf("\n(BasexHeight) | Area | | |\n");
printf("------------------------------------------------------------------------------\n");
11
CBCP2103
/* Nested Loop used to create the table of value*/
float i, j, b, h, csa, I, Z;
for (i=1; i<=5; i++){
b=2*i; /* b = base, defining values for b */
for (j=1; j<=6; j++){
h=2*j; /* h = height, defining values for h */
csa=b*h; /* csa = Cross Sectional Area */
I=(b*(h*h*h))/12; /* I = Moment of Inertia */
Z=(b*(h*h))/6; /* Z = Section Modulus */
printf(" %2.f x %2.f | %3.f | %10.2f | %10.2f |\n", b, h, csa, I, Z);
}
}
getch();
return 0;
}
2.2 Screenshots for Question 2
12
CBCP2103
Picture 2.2.1. Screenshot for displaying lumber size and its engineering properties.
2.3 Flowchart for Question 2
13
CBCP2103
3.0 REFERENCE
14
CBCP2103
Bakar, M. A. et al. (2011). CBCP2103 Computer Programming (2nd ed.). Centre for Instructional Design and Technology: Open University Malaysia.
Compiler used: Dev-C++ version 4.9.9.2 (provided by Open University Malaysia). Available: http://download.oum.edu.my/fitmc/m.php?p=compilers/devcpp-4.9.9.2_setup.exe
Cprogramming .com-Your resources for C and C++ [online]. Available: http://www.cprogramming .com
C programming tutorial [online]. Available: http://thenewboston.org/list.php?cat=14.
OPEN UNIVERSITY MALAYSIA online forum [online]. Available: http://lms.oum.edu.my.
15