0% found this document useful (0 votes)
355 views15 pages

Assignment Cbcp2103 Semsept 1012

This document contains code and explanations for two programming questions. Question 1 involves coding a program to calculate water bills for different customer types. Question 2 involves coding a program to output a table of engineering properties for different lumber sizes. The coding, screenshots, and flowcharts for each question are presented across multiple pages. Key details like the student name, course, and semester are provided at the top.

Uploaded by

Marilyn Low
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
355 views15 pages

Assignment Cbcp2103 Semsept 1012

This document contains code and explanations for two programming questions. Question 1 involves coding a program to calculate water bills for different customer types. Question 2 involves coding a program to output a table of engineering properties for different lumber sizes. The coding, screenshots, and flowcharts for each question are presented across multiple pages. Key details like the student name, course, and semester are provided at the top.

Uploaded by

Marilyn Low
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

SEPTEMBER SEMESTER 2012

CBCP2103

COMPUTER PROGRAMMING TUTOR: YUZERY BIN YUSOFF

MATRICULATION NO IDENTITY CARD NO. TELEPHONE NO. E-MAIL LEARNING CENTRE

: : : : :

R336825001 A1031320 012-2856722 [email protected] 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 210 2.2 Screenshots for Question 2.12 2.3 Flowchart for Question 2....13 References.14

CBCP2103

1.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 */ int main() { printf("\nWATER COMPANY BILLING SYSTEM\n"); /* Heading of the system */ printf("=============================\n\n");

int accountNo; char codeType; double waterAmount, bill;

printf("Please enter your account no: number */ scanf("%d", &accountNo);

"); /* Enter user's account

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): code of the user */ scanf("\n%c", &codeType); printf("Now enter water amount (gallons): of water used */ scanf("%lf", &waterAmount);

CBCP2103 "); /* Enter usage

"); /* Enter the quantity

/* 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 if (waterAmount > 10000000) bill = 3000; break; default : printf("\nERROR!! You entered wrong code!!\n\n"); /* If the code type entered other than h or c or i */ }

CBCP2103 printf("bill = %lf\n", bill); printf("=============================\n\n"); printf("You need to pay: RM %.2lf", bill);

getch(); return 0; }

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.

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.

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.

CBCP2103

Picture 1.2.7. Screenshot for displaying when user input code type other than h / c /i.

CBCP2103

1.3 Flowchart for Question 1


start

Prompt user to input account number

Input code type of water usage (h/c/i)

Input water amount

case h (home usage)

yes

bill = 5.00 + (0.0005 x water amount)

no yes

case c (commercial)

yes

if water amount <= 4million gallons

bill = 1000

no

no bill = ((water amount 4million) x 0.00025) + 1000

else-if water amount > 4million gallons

case i (industry)

yes

yes
if water amount <= 4million gallons

bill = 1000

no

no yes

else-if 4million<water amount>=10million (gallons)

bill = 2000

no

else water amount >10million gallons

bill = 3000

default: other than h/c/i

Display ERROR! You entered wrong code

Display the bill that need to be paid by user

end

CBCP2103

2.0 Question 2 (Table of the Engineering Properties for Bunyan Lumber Company). 2.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> int main() {

/* Defining Standard Input Output routines */

printf("\n\t\t\tBUNYAN LUMBER COMPANY\n"); system */ printf("\n\t\t Engineering Properties of

/* Heading for the

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) |\n"); | Area |

printf("-----------------------------------------------------------------------------\n");

/* Nested Loop used to create the table of value*/ float base, height, csa, I, Z;

10

CBCP2103 for (base=2; base<=10; base+=2){ for (height=2; height<=12; height+=2){ csa=base*height; /* csa = Cross Sectional Area */ /* I = Moment of Inertia */ /* Z = Section Modulus */ |

I=(base*pow(height,3))/12; Z=(base*pow(height,2))/6;

%10.2f

printf(" %2.f x %2.f | %3.f | %10.2f |\n", base, height, csa, I, Z);

} } getch(); return 0; }

11

CBCP2103

2.2 Screenshots for Question 2

Picture 2.2.1. Screenshot for displaying lumber size and its engineering properties.

12

CBCP2103

2.4 Flowchart for Question 2

start

base = 2

False base<=10 True

height = 2

height<=12 True

False

Calculation: csa = base x height I= Z=


base x 3 12 2 6

height+=2

base+=2

end

13

CBCP2103

3.0 REFERENCE 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/devcpp4.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.

14

You might also like