SlideShare uma empresa Scribd logo
1 de 4
FP 201 – PROGRAMMING FUNDAMENTALS




LAB 5 : PROGRAM CONTROL
Learning Outcome

By the end of this lab, students should be able to :
• Describe the structure of for, while and do..while statements in C+
    + program
• Write program using looping statements

Theory/ Topics

•   Relational Operator (<, <=, >, >=)
•   Logical Operator (&&, ||)
•   Operator Precedence
•   Expression
•   Looping statements – for, while, do..while statements

Procedure :
Step 1: Type the programs given below
Step 2: Save the program as _________________
Step 3: Compile and run the program. Write the output


Activity 5A

#include<iostream>
using namespace std;
void main()
{
        int x;
        for(x=1; x<=5; x++)
        {         if (x==3)
                           continue;
                  cout<<x;
        }
        return 0;
}




                                                                    1
FP 201 – PROGRAMMING FUNDAMENTALS




Activity 5B

#include<iostream>
using namespace std;
void main()
{
        int x;
        for(x=1; x<=5; x++)
        {         if (x==3)
                           break;
                  cout<<x;
        }
        return 0;
}


Activity 5C

//Program that add an integer to itself for n of times.
#include <iostream>
using namespace std;
void main()
    {
  int number1, number2;
    int total = 0;
   cout << "Please enter 2 numbers: ";
   cin >> number1 >> number2;

 for(int i = 0; i < number2; ++i)
   {
   total += number1;
     }
  cout << "Total addition: " << total;
  }




                                                          2
FP 201 – PROGRAMMING FUNDAMENTALS




Activity 5D

The following program illustrate the syntax of do..while
statements.

#include <iostream>
using namespace std;
void main()
     {
     char ch;
     int n1, n2;
     do
        {
        cout << “Enter number 1 : “;
        cin >> n1;
        cout << “Enter number 2 : “;
        cout << “number 1 divide by number 2 : “ << n1/n2
         << “, remainder is : “ << n1%n2 << endl;
        cout << “nDo another ? (y/n) => “;
        cin >> ch;
          } while (ch != ‘n’);
     }


Activity 5E
The following program illustrate the syntax of while statements.

#include <iostream>
using namespace std;
void main()
{
         char ch = ‘y’;
         int n1, n2;

         while (ch != ‘n’)
         {
                  cout << “Enter number 1 : “;
                  cin >> n1;
                  cout << “Enter number 2 : “;



                                                                   3
FP 201 – PROGRAMMING FUNDAMENTALS



                  cout << “number 1 divide by number 2 : “ << n1/n2
                  << “, remainder is : “ << n1%n2 << endl;
                  cout << “nDo another ? (y/n) => “;
                  cin >> ch;
         }
}



Exercise 5.1

Write programs to print the following patterns:

                    1
                    12
                    123
                    1234

Exercise 5.2

Write a program by using while loops to calculate the parking fee based
on parking rate RM2.00 per hour for every customer. When there are
no more customers, your program should be able to sum the total
parking collection.
         Example of output:
         Enter parking hours: 2
         Parking fee: RM 4
         Continue? (y/n) => y
         Enter parking hours: 5
         Parking fee: RM 10

         Continue? (y/n) => n
         Total collection: 14




                                                                      4

Mais conteúdo relacionado

Mais procurados

Lab 9 sem ii_12_13
Lab 9 sem ii_12_13Lab 9 sem ii_12_13
Lab 9 sem ii_12_13
alish sha
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
rohassanie
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
alish sha
 
Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4
emailharmeet
 
A1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_solA1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_sol
malasumathi
 
Programing array and function
Programing array and functionPrograming array and function
Programing array and function
rowntu
 

Mais procurados (20)

Lab 9 sem ii_12_13
Lab 9 sem ii_12_13Lab 9 sem ii_12_13
Lab 9 sem ii_12_13
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
 
Do while loop
Do while loopDo while loop
Do while loop
 
Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4
 
เฉลยแบบฝึกหัดบทที่ 1
เฉลยแบบฝึกหัดบทที่ 1เฉลยแบบฝึกหัดบทที่ 1
เฉลยแบบฝึกหัดบทที่ 1
 
Lab 1
Lab 1Lab 1
Lab 1
 
Control flow Graph
Control flow GraphControl flow Graph
Control flow Graph
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
Computer science project work
Computer science project workComputer science project work
Computer science project work
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation
 
A1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_solA1 spyder variables_operators_nptel_pds1_sol
A1 spyder variables_operators_nptel_pds1_sol
 
Compiling CAO: From Cryptographic Specifications to C Implementations
Compiling CAO: From Cryptographic Specifications to C ImplementationsCompiling CAO: From Cryptographic Specifications to C Implementations
Compiling CAO: From Cryptographic Specifications to C Implementations
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
 
up down Counter Verilog
up down Counter Verilogup down Counter Verilog
up down Counter Verilog
 
Programing array and function
Programing array and functionPrograming array and function
Programing array and function
 
Implementing stack
Implementing stackImplementing stack
Implementing stack
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 

Semelhante a Labsheet 5

Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 stud
rohassanie
 
Assignement of programming & problem solving ass.(3)
Assignement of programming & problem solving ass.(3)Assignement of programming & problem solving ass.(3)
Assignement of programming & problem solving ass.(3)
Syed Umair
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
rohassanie
 
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
Week 2PRG 218   Variables and Input and Output OperationsWrite.docxWeek 2PRG 218   Variables and Input and Output OperationsWrite.docx
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
melbruce90096
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
IIUM
 
Week 2PRG 218Variables and Input and Output OperationsWrite .docx
Week 2PRG 218Variables and Input and Output OperationsWrite .docxWeek 2PRG 218Variables and Input and Output OperationsWrite .docx
Week 2PRG 218Variables and Input and Output OperationsWrite .docx
co4spmeley
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
Prabhu D
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
alish sha
 

Semelhante a Labsheet 5 (20)

Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 stud
 
Labsheet2
Labsheet2Labsheet2
Labsheet2
 
Assignement of programming & problem solving ass.(3)
Assignement of programming & problem solving ass.(3)Assignement of programming & problem solving ass.(3)
Assignement of programming & problem solving ass.(3)
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
 
Labsheet 4
Labsheet 4Labsheet 4
Labsheet 4
 
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
Week 2PRG 218   Variables and Input and Output OperationsWrite.docxWeek 2PRG 218   Variables and Input and Output OperationsWrite.docx
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
C-LOOP-Session-2.pptx
C-LOOP-Session-2.pptxC-LOOP-Session-2.pptx
C-LOOP-Session-2.pptx
 
Week 2PRG 218Variables and Input and Output OperationsWrite .docx
Week 2PRG 218Variables and Input and Output OperationsWrite .docxWeek 2PRG 218Variables and Input and Output OperationsWrite .docx
Week 2PRG 218Variables and Input and Output OperationsWrite .docx
 
Python programming workshop session 4
Python programming workshop session 4Python programming workshop session 4
Python programming workshop session 4
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
 
4. programing 101
4. programing 1014. programing 101
4. programing 101
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1stud
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
 
Operating System Lab Manual
Operating System Lab ManualOperating System Lab Manual
Operating System Lab Manual
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 

Mais de rohassanie

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012
rohassanie
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
rohassanie
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
rohassanie
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5
rohassanie
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2
rohassanie
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1
rohassanie
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
rohassanie
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
rohassanie
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
rohassanie
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2)
rohassanie
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201
rohassanie
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012
rohassanie
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
rohassanie
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
rohassanie
 
Chapter 1 part 3
Chapter 1 part 3Chapter 1 part 3
Chapter 1 part 3
rohassanie
 
Chapter 1 part 2
Chapter 1 part 2Chapter 1 part 2
Chapter 1 part 2
rohassanie
 

Mais de rohassanie (20)

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Lab ex 1
Lab ex 1Lab ex 1
Lab ex 1
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2)
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 
Chapter 1 part 3
Chapter 1 part 3Chapter 1 part 3
Chapter 1 part 3
 
Chapter 1 part 2
Chapter 1 part 2Chapter 1 part 2
Chapter 1 part 2
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Labsheet 5

  • 1. FP 201 – PROGRAMMING FUNDAMENTALS LAB 5 : PROGRAM CONTROL Learning Outcome By the end of this lab, students should be able to : • Describe the structure of for, while and do..while statements in C+ + program • Write program using looping statements Theory/ Topics • Relational Operator (<, <=, >, >=) • Logical Operator (&&, ||) • Operator Precedence • Expression • Looping statements – for, while, do..while statements Procedure : Step 1: Type the programs given below Step 2: Save the program as _________________ Step 3: Compile and run the program. Write the output Activity 5A #include<iostream> using namespace std; void main() { int x; for(x=1; x<=5; x++) { if (x==3) continue; cout<<x; } return 0; } 1
  • 2. FP 201 – PROGRAMMING FUNDAMENTALS Activity 5B #include<iostream> using namespace std; void main() { int x; for(x=1; x<=5; x++) { if (x==3) break; cout<<x; } return 0; } Activity 5C //Program that add an integer to itself for n of times. #include <iostream> using namespace std; void main() { int number1, number2; int total = 0; cout << "Please enter 2 numbers: "; cin >> number1 >> number2; for(int i = 0; i < number2; ++i) { total += number1; } cout << "Total addition: " << total; } 2
  • 3. FP 201 – PROGRAMMING FUNDAMENTALS Activity 5D The following program illustrate the syntax of do..while statements. #include <iostream> using namespace std; void main() { char ch; int n1, n2; do { cout << “Enter number 1 : “; cin >> n1; cout << “Enter number 2 : “; cout << “number 1 divide by number 2 : “ << n1/n2 << “, remainder is : “ << n1%n2 << endl; cout << “nDo another ? (y/n) => “; cin >> ch; } while (ch != ‘n’); } Activity 5E The following program illustrate the syntax of while statements. #include <iostream> using namespace std; void main() { char ch = ‘y’; int n1, n2; while (ch != ‘n’) { cout << “Enter number 1 : “; cin >> n1; cout << “Enter number 2 : “; 3
  • 4. FP 201 – PROGRAMMING FUNDAMENTALS cout << “number 1 divide by number 2 : “ << n1/n2 << “, remainder is : “ << n1%n2 << endl; cout << “nDo another ? (y/n) => “; cin >> ch; } } Exercise 5.1 Write programs to print the following patterns: 1 12 123 1234 Exercise 5.2 Write a program by using while loops to calculate the parking fee based on parking rate RM2.00 per hour for every customer. When there are no more customers, your program should be able to sum the total parking collection. Example of output: Enter parking hours: 2 Parking fee: RM 4 Continue? (y/n) => y Enter parking hours: 5 Parking fee: RM 10 Continue? (y/n) => n Total collection: 14 4