Preview

Csc238

Satisfactory Essays
Open Document
Open Document
875 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Csc238
OBJECT ORIENTED PROGRAMMING CSC238

Lecture 3 – Common Algorithms

Lecture 3

Objectives
Common Algorithms
Total T l Average Counting Minimum value and maximum value
Ranged value Unlimited l U li i d value

1

Mohd Hanapi Abdul Latif

Total / Sum group of values
The algorithm in this application may be used to solve sol e problem such as s ch
To calculate the total of payment for N employees; To sum the amount that a customer has to pay; To calculate the total of salary that a person receives in a year; and To l l t the total T calculate th t t l payment of ticket f a show. t f ti k t for h

Mohd Hanapi Abdul Latif

Total / Sum group of values
Steps Example – display the sum of 10 prices double price, sumPrice; p , ; sumPrice=0.0; 1. Introduce a variable to store the sum of values and initial it to zero. 2. In a repetition structure, sum the a number.

for (int bil = 0; bil < 10; bil++) { //input and sum value of price price=inp.nextDouble(); sumPrice= sumPrice + price; } System.out.println(“The sum prices is RM: ”+sumPrice); of 10

3. Display or use the summed value after the loop

2

Mohd Hanapi Abdul Latif

Common mistakes
Variable to sum numbers is not initialized Variable to sum numbers is initialized in the loop. p for (int cnt=0; cnt < 10; cnt++) { sumNum = 0.0; System.out.print ("Enter a number: "); no = inp.nextDouble(); sumNum += no; } Incorrect arithmatic expression to sum numbers. for (int cnt=0; cnt < 10; cnt++) { : no = inp.nextDouble(); sumNum = no; : }

Mohd Hanapi Abdul Latif

Counting of occurrence
Counting the occurrence of item such as the number of odd values, h b f dd l the numbers of all values that the user keys in, the number of male gender, the number of students that have cgpa between 3.00 until 4.00

3

Mohd Hanapi Abdul Latif

Steps

Example – count the number of prices that is higher than RM50.00 g

1) Introduce a variable of type double price; int and initial it to zero. int

You May Also Find These Documents Helpful

  • Powerful Essays

    POW 9 IMP3

    • 1192 Words
    • 5 Pages

    Create 2 formulas, one that will calculate the last number in terms of the first number and a constant increase in rate as well as the total amount of numbers. The second formula will add ass of the resulting numbers from the first formula together after the last number is calculated.…

    • 1192 Words
    • 5 Pages
    Powerful Essays
  • Good Essays

    ops335 lab 2 firewall

    • 695 Words
    • 4 Pages

    4. Enter the list price of the book and include a dollar sign in the prompt. Make the list price a decimal data type or test to ensure that the user entered a numerical value.…

    • 695 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Eco 550 Assignment 1

    • 932 Words
    • 4 Pages

    Figure 1: Total Cost (TC), Total Variable Cost (TVC) and Total Fixed Cost (TFC) functions…

    • 932 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Pt1420 week 2

    • 320 Words
    • 3 Pages

    1. Design an algorithm that prompts the user to enter his or her height and stores the user’s input in a variable named height.…

    • 320 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Acc 201

    • 272 Words
    • 2 Pages

    |(Actual input quantity x Actual price) |(Actual input quantity x Budgeted price) |(Budgeted input quantity |…

    • 272 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pt1420 Assignment

    • 1058 Words
    • 5 Pages

    2) Design a Do-While loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user if he or she wishes to perform the operation again. If so, the loop should repeat, otherwise it should terminate…

    • 1058 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    Andre's Hair Styling

    • 573 Words
    • 3 Pages

    Selling price per unit= $12 and variable cost per unit =$.40 = $12 – 0.40 =$11.60…

    • 573 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    HSC3003

    • 692 Words
    • 2 Pages

    to make as many decisions about their care as possible and to support the individuals to do as…

    • 692 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Psyc2301

    • 388 Words
    • 2 Pages

    1. Label each structure as belonging to the (a) central nervous system or (b) peripheral nervous system…

    • 388 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    CS320 Lab1

    • 874 Words
    • 3 Pages

    item’s cost. The solution is then multiplied by 100 to determine the profit percentage for…

    • 874 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    unit 3

    • 313 Words
    • 2 Pages

    6. Write a pseudocode statement that declares the variable total so it can hold real integers. Initialize the variable with the value 0.…

    • 313 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Hsc2028

    • 548 Words
    • 3 Pages

    There are a number of conditions that can have an impact on the correct movement and positioning of people.…

    • 548 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    CT236

    • 372 Words
    • 2 Pages

    1.1 Duty of Care means the requirement to provide as much care as reasonably possible to avoid service users from ant harm and to avoid injury to the individual.…

    • 372 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    CU235P

    • 1045 Words
    • 5 Pages

    Health and social care organisations have what is called a duty of care towards the people they look after. That means that they must do everything they can to keep the people in their care safe from harm. It is not only the care establishment that needs to prioritise the safety, welfare and interests of the people using its services, but also the care workers of the establishment. My employer also has a duty of care for staff members, to ensure that working conditions are safe, and suitable to deliver the service.…

    • 1045 Words
    • 5 Pages
    Satisfactory Essays
  • Satisfactory Essays

    300.00 290.00 303.75 316.00 390.00 515.00 392.31 542.31 348.46 1,000.00 4,397.83 4 $13.07 52.28 234.57 1.25 $19.32 24.15 6 $11.85 71.10 8 $10.88 87.04…

    • 703 Words
    • 3 Pages
    Satisfactory Essays