The document discusses different control structures in C++ programs that allow for flow of execution. There are three main control structures: sequential, selection, and repetition. The sequential structure executes statements in order without branching. The selection structure (if/else, switch) allows for decisions and choosing between code blocks. The repetition structure (loops) allows code to repeat until a condition is met.
MALAYSIA : KESEPADUAN DAN KEPELBAGAIAN
PENSYARAH : USTAZAH SUMAIYAH BINTI BAHRI
FAKULTI SENIBINA PERANCANGAN DAN UKUR
PEMBENTANG
1.NUR AUFA BINTI NAZRI
2.NURUL NADHIRAH BINTI ZULKEFLI
3.WAN NUR IZZATI BINTI WAN MOHD YUSLI
4. NUR FARAHAIN BINTI JAMAL
Dengan melakukan beberapa pemerhatian tentang tajuk ini, kami baru meyedari bahawa terlalu banyak terjadinya budaya ini kepada orang Islam di Malaysia. Nauzubillah.
MALAYSIA : KESEPADUAN DAN KEPELBAGAIAN
PENSYARAH : USTAZAH SUMAIYAH BINTI BAHRI
FAKULTI SENIBINA PERANCANGAN DAN UKUR
PEMBENTANG
1.NUR AUFA BINTI NAZRI
2.NURUL NADHIRAH BINTI ZULKEFLI
3.WAN NUR IZZATI BINTI WAN MOHD YUSLI
4. NUR FARAHAIN BINTI JAMAL
Dengan melakukan beberapa pemerhatian tentang tajuk ini, kami baru meyedari bahawa terlalu banyak terjadinya budaya ini kepada orang Islam di Malaysia. Nauzubillah.
This page contains examples and source code on decision making in C programming (to choose a particular statement among many statements) and loops ( to perform repeated task ). To understand all the examples on this page, you should have knowledge of following topics:
if...else Statement
for Loop
while Loop
break and Continue Statement
switch...case
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
The slides from the C++ and OOPS Crash Course conducted for ACM DBIT by Grejo Joby.
Learn the concepts of OOPS and C++ Programming in the shortest time with these notes.
Detailing about basics of C language and its control structure for learning C Language for beginners. It covers looping statement , control statement etc.
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
Keep tabs on your field staff effortlessly with Informap Technology Centre LLC. Real-time tracking, task assignment, and smart features for efficient management. Request a live demo today!
For more details, visit us : https://informapuae.com/field-staff-tracking/
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
Enterprise Resource Planning System includes various modules that reduce any business's workload. Additionally, it organizes the workflows, which drives towards enhancing productivity. Here are a detailed explanation of the ERP modules. Going through the points will help you understand how the software is changing the work dynamics.
To know more details here: https://blogs.nyggs.com/nyggs/enterprise-resource-planning-erp-system-modules/
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
We explore the Globus Connect Server (GCS) architecture and experiment with advanced configuration options and use cases. This content is targeted at system administrators who are familiar with GCS and currently operate—or are planning to operate—broader deployments at their institution.
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
How Recreation Management Software Can Streamline Your Operations.pptxwottaspaceseo
Recreation management software streamlines operations by automating key tasks such as scheduling, registration, and payment processing, reducing manual workload and errors. It provides centralized management of facilities, classes, and events, ensuring efficient resource allocation and facility usage. The software offers user-friendly online portals for easy access to bookings and program information, enhancing customer experience. Real-time reporting and data analytics deliver insights into attendance and preferences, aiding in strategic decision-making. Additionally, effective communication tools keep participants and staff informed with timely updates. Overall, recreation management software enhances efficiency, improves service delivery, and boosts customer satisfaction.
2. PROGRAM CONTROL STRUCTURE
• Program control structure controls the flow of
execution of program statement.
• C++ provides structures that will allow an
instruction or a block of instruction to be
executed, repeated and skipped.
• There are three control structure:
sequential structure
selection structure
repetition structure
3. Sequence structure
• The sequence structure has one entry point
and one exit point.
• No choice are made and no repetition.
• Statement are executed in sequence, one
after another without leaving out any single
statement.
5. Example of sequential statement
#include<iostream>
using namespace std;
int main()
{
float payrate=8.5;
float hourWorked=25.0;
float wages;
wages= hourWorked * payrate;
cout<<“n Wages = RM:”<<wages<<endl;
return 0;
}
Output:
Wages = RM:212.5
6. Example of sequential statement
include<iostream>
using namespace std;
int main()
{
int num1,num2;
float total;
cout<<“NUMBER 1:”;
cin>>num1;
cout<<“NUMBER 2:”;
cin>>num2;
total=num1+num2;
cout<<“TOTAL OF TWO NUMBERS IS:”<<total<<endl;
return 0;
}
Output:
NUMBER 1:10
NUMBER 2:5
TOTAL OF TWO NUMBERS IS:15
7. Selection structure
• The selection structure is used to allow
choices to be made.
• This program executes particular statements
depending on some condition(s).
• C++ uses if..else, nested if and switch..case
statement for making decision.
8. Selection statement
If…else
• A selection of control structure is used to select
between two or more options.
• Used to make decision based on condition.
• else statement will never exist in a program
without if statement.
• If tested condition is TRUE, the entire block of
statements following the if is performed.
• If the tested condition is FALSE, the entire block
of statement following the else is performed
11. Example of if..else statement
#include<iostream>
using namespace std;
int main()
{
int age;
cout<<“n Key in your age:”<<age;
cin>>age;
if(age>21)
{
cout<<“Qualifiied to have driving license”;
}
else
{
cout<<“Not qualified to have driving license”;
}
return 0;
}
Output:
Key in your age:18
Not qualified to have driving license
Output:
Key in your age:25
Qualifiied to have driving license
Output:
Key in your age:21
Not qualified to have driving license
14. • In this nested form, condition 1 is evaluated. If it
is zero, statement D is executed and the entire
nested if statement is terminated.
• In not, control goes to the second if and condition
2 is evaluated. If it is zero, statement C is
executed.
• If not, control goes to the third if and condition 3
is evaluated. If it is zero, statement B is executed .
• If not , statement A executed.
15. Example of statement#include<iostream>
using namespace std;
int main()
{
float cgpa,salary;
int year;
cout<<“n YEAR:”;
cin>>year;
cout<<“n CGPA:”;
cin>>cgpa;
cout<<“n SALARY:”;
cin>>salary;
if(year>1)
{
if(cgpa>=3.00)
{
if(salary<=500)
{
cout<<“Your application is under consideration”;
}
else
{
cout<<“Not success because salary is more than RM500.00“;
}
}
else
{
cout<<“ Not success because cgpa is less than 3.00”;
}
}
else
{
cout<<“ Not success because yeaa of study is less than 1”;
}
return 0;
Output:
YEAR:2
CGPA:3.5
SALARY:250
Your application is under consideration
19. Usage of Logical Operator
Symbol
(pseudocode)
Symbol
(c++ language)
Example Result Description
AND && (1>3)&&(10<20) FALSE Both sides of
the condition
must be true.
OR || (1>3)&&(10<20) TRUE Either one of
the condition
must be true.
NOT ! !(10<20) FALSE Change the
operation
either from
true to false or
vise versa.
20. Example using of AND operator
● If condition ( num1< num2) is true AND condition ( num1 > num3) is true
then print “First number is the largest number” will be displayed.
● If one of the condition is not true then print “First number is the largest
number” will not be displayed.
If ((num1 > num2 ) && ( num1 > num3 ))
cout<<“First number is the largest number”;
21. Example usage of OR operator:
● if the sales are more than 5000 or working hours
are more than 81, bonus RM500 will be given. If
either condition is not fulfilled, still the amount of
RM500 will be given as bonus.
● If both condition are false, then bonus will not be
given.
If ( ( sales > 5000 ) || (hourseworked > 81 ))
Bonus = 500;
else
22. Switch case
• The switch..case structure consists of a series of case label
and optional default case which can be included for option
that is not listed in the case label.
• Switch which is followed by variable name in parentheses
called controlling expression.
• The break keyword must be included at the end of each
case statement.
• The break statement causes program control to proceed
with the first statement after the switch structure.
• Without break statement, all command for that case and
next case label will be executed.
• Default is an option that will only be executed if suitable
case cannot be found.
25. Example of program
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<“n Enter a number:”;
cin>>num;
switch(num)
{
case 1:
cout<<“Welcome”;
break;
case 2:
cout<<“Bye”;
break;
default:
cout<<“Wrong Number”;
}
return 0;
Output:
Enter a number:1
Welcome
26. Example of program without break
statement
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<“n Enter a number:”;
cin>>num;
switch(num)
{
case 1:
cout<<“Welcome”;
case 2:
cout<<“Bye”;
default:
cout<<“Wrong Number”;
}
return 0;
Output:
Enter a number:1
WelcomeByeWrong Number
27. Example of program
#include<iostream>
using namespace std;
int main()
{
char grade;
cout<<“n Enter a grade (A-D):”;
cin>>grade;
switch(grade)
{
case ‘A’:
cout<<“Minimun marks is 80”;
break;
case ‘B’:
cout<<“Minimun marks is 60”;
break;
case ‘C’:
cout<<“Minimun marks is 40”;
break;
case ‘D’:
cout<<“Minimun marks is 25”;
break;
default:
cout<<“Mark between 0-24”;
}
return 0;
}
Output:
Enter a grade (A-D):C
Minimun mark is 40
28. • A,B,C, and D are the possible values that can be assigned to the
variable grade.
• In each case of constant, A to D a statement or sequence of
statement would be executed.
• You would have noticed that every line has statement under it
called break.
• The break is the only thing that stop a case statement from
continuing all the way down through each case label under it.
• In fact if you do not put break in, the program will keep going down
in the case statement. Into other case labels, until it reaches the
end of break.
• However the default part is the codes that would be executed if
there were no matching case of constant’s value.
29. Rules for Switch statement
• The value of case statement must be an integer or a
character constant.
• Case statement arrangement is not important.
• Default can exist earlier ( but compiler will place it at
the end)
• Can’t use condition or limit.
• Why switch is the best way to write a program:
easy to read
It is a more spesific statement to implement multiple
alternative decisions.
It is used to make a decision between many alternative.
30. Comparison of Nested if statement
and switch..case statement
Nested if statement switch.. case statement
#include<iostream>
using namespace std;
int main()
{
int code;
cout<<“Enter code (1,2 or 3)”;
cin>>code;
if(code==1)
cout<<“Your favourite flavor is vanila”;
else if(code==2)
cout<<“Your favourite flavor is chocolate”;
else if(code==3)
cout<<“Your favourite flavor is strawbery”
else
cout<<“please choose code 1,2 or 3 only”;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int code;
cout<<“Enter code (1,2 or 3)”;
cin>>code;
switch(code)
{
case1:
cout<<“Your favourite flavor is vanila”;
break;
case2:
cout<<“Your favourite flavor is chocolate”;
break;
case 3:
cout<<“Your favourite flavor is strawbery”;
default:
cout<<“please choose code 1,2 or 3 only”;
}
return 0;
}
31. exercise
1. If the payment RM5,000 to RM10,000, display a message that the
customer will be given a free ticket to Langkawi. Otherwise, display a
message that the customer will only be given a free lunch at Quality
Hotel. Translate the statement above to program segment.
2. You are given the following requirement:
a. Your program is able to read the amount of sales for a sale executive.
b. If the sale is more than RM10,000 then the commission will be 5% of the
sale. Otherwise, the commission is only 3% of the sales.
c. Your program is able to calculate the amount of commission by multiply the
percentage of commission with sale.
d. Your program is able to display the amount of commission to the sale
executive.
3. Write a c++ program to find a maximum value of three integers which are
a, b and c.
32. exercise
4. You’re given the following requirements:
a. Your program is able to read the item code from the keyboard
b. The item code determines the price for each item in the shop. The following table shows
the prices and charges of 7 items in the shop.
c. If the item code is not matched, an error message is dispayed as follows:
“Error, this item code is not in the list.”
d. For each selected item, the charge is calculated by multiplying the item price and charge rate.
e. Then the payment is a summation of item price and charge. Your program is to display this
payment.
Item Code Price (RM) Charge(%)
A 54.00 5
B 65.00 5
C 82.00 5
D 103.00 7
E 150.00 7
F 245.00 10
H 250.00 10
33. exercise
4. NASA Consultant Co Ltd wants to develop a program that can help the consultant
to give advice regarding the home loan. The program receives two inputs from the
consultant, which are the amount of House Cost in Ringgit Malaysia and years of
term applied. Based on these two inputs, the program should be able to calculate
the monthly repayment. The table for the interest calculation is provided as follows:
The formulae for the monthly repayment calculation are as follows:
Interest (RM) = Interest (%) x House cost (RM)
House cost with Interest = House Cost (RM) + Interest (RM)
Monthly Repayment = House Cost with Interest / ( Year of Term Applied x 12)
Year of Term Applied Interest (%)
More than or equal to 25 years 7.5
More than or equal to 20 years 6.5
More than or equal to 15 years 5.5
More than or equal to 10 years 4.5
Less than 10 years 4.0
34. Answer for question 1
(if else)
#include<iostream>
using namespace std;
int main()
{
float payment;
cout<<"Please enter your payment:RM";
cin>>payment;
if(payment>=5000&&payment<=10000)
{
cout<<"Free air ticket to Langkawi";
}
else
{
cout<<"Free lunch at Quality Hotel";
}
return 0;
35. Answer for question 1
(nested if)#include<iostream>
using namespace std;
int main()
{
float payment;
cout<<"Please enter your payment:RM";
cin>>payment;
if(payment>=5000)
{
if(payment<=10000)
cout<<"Free air ticket to Langkawi";
else
cout<<"Free lunch at Quality Hotel";
}
else
cout<<"Free lunch at Quality Hotel";
return 0;
}
36. Answer for question 1
if and if else#include<iostream>
using namespace std;
int main()
{
float payment;
cout<<"Please enter your payment:RM";
cin>>payment;
{
if(payment>10000)
{
cout<<"Free lunch at Quality Hotel";
cout<<"ccc";
}
}
{
if(payment>=5000)
{
cout<<"Free air ticket to Langkawi";
cout<<"hiii";
}
else
{
cout<<"Free lunch at Quality Hotel";
cout<<"bye";
}
}
return 0;
}
37. Answer for question 2
#include<iostream>
using namespace std;
int main()
{
float sale,commission,amount_commission;
cout<<"Please enter your sale:RM";
cin>>sale;
if(sale>10000)
{
commission=0.05;
}
else
{
commission=0.03;
}
amount_commission=sale*commission;
cout<<"Your amount of commission is:RM"<<amount_commission;
return 0;
}
38. Answer for question 2
#include<iostream>
using namespace std;
int main()
{
float sale,commission,amount_commission;
cout<<"Please enter your sale:RM";
cin>>sale;
if(sale>10000)
{
commission=0.05;
amount_commission=sale*commission;
cout<<"Your amount of commission is:RM"<<amount_commission;
}
else
{
commission=0.03;
amount_commission=sale*commission;
cout<<"Your amount of commission is:RM"<<amount_commission;
}
return 0;
}
39. Answer question 5
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"ENTER FIRST NUMBER:";
cin>>a;
cout<<"ENTER SECOND NUMBER:";
cin>>b;
cout<<"ENTER THIRD NUMBER:";
cin>>c;
cout<<"n*****************************n";
if(a>b&&a>c)
{
cout<<"MAXIMUM VALUE IS:"<<a;
}
else if(b>a&&b>c)
{
cout<<"MAXIMUM VALUE IS:"<<b;
}
else
{
cout<<"MAXIMUM VALUE IS:"<<c;
}
return 0;
}
40. Answer for question 6
#include<iostream>
using namespace std;
int main()
{
char code;
float price,charge_rate,charge,payment;
cout<<"ITEM CODE:";
cin>>code;
switch(code)
{
case 'A':price=54.00;
charge_rate=0.05;
charge=price*charge_rate;
payment=price+charge;
cout<<"Your payment is:RM"<<payment;
break;
case 'B':price=65.00;
charge_rate=0.05;
charge=price*charge_rate;
payment=price+charge;
cout<<"Your payment is:RM"<<payment;
break;
case 'C':price=82.00;
charge_rate=0.05;
charge=price*charge_rate;
payment=price+charge;
cout<<"Your payment is:RM"<<payment;
break;
41. case 'D':price=103.00;
charge_rate=0.07;
charge=price*charge_rate;
payment=price+charge;
cout<<"Your payment is:RM"<<payment;
break;
case 'E':price=150.00;
charge_rate=0.07;
charge=price*charge_rate;
payment=price+charge;
cout<<"Your payment is:RM"<<payment;
break;
case 'F':price=245.00;
charge_rate=0.1;
charge=price*charge_rate;
payment=price+charge;
cout<<"Your payment is:RM"<<payment;
break;
case 'H':price=250.00;
charge_rate=0.1;
charge=price*charge_rate;
payment=price+charge;
cout<<"Your payment is:RM"<<payment;
break;
default:
cout<<"Error, this item code is not in the listn";
}
return 0;
}
42. Answer for question 7
#include<iostream>
Using namespace.std;
int main()
{
float House_cost,monthly_repayment,interest,interest_pay,House_cost_ineterest;
int year;
cout<<"HOUSE COST IN RM:";
cin>>House_cost;
cout<<"YEAR OF TERM APPLIED:";
cin>>year;
if(year>=25)
{
interest=0.75;
}
else if(year>=20&&year<25)
{
interest=0.65;
}
else if(year>=15&&year<20)
{
interest=0.55;
}
else if(year>=10&&year<15)
{
interest=0.45;
}
else
{
interest=0.40;
}
interest_pay=interest*House_cost;
House_cost_ineterest=House_cost+interest_pay;
monthly_repayment=House_cost_ineterest/(year*12);
cout<<"YOUR REPAYMENT A MONTH IS:RM"<<monthly_repayment;
return 0;
}
43. Repetition structure
• Why repetition is needed??
• Suppose we want to add five numbers to find their
average.
• From what we have learned so far, we could proceed as
follows.
cin>>num1>>num2>>num3>>num4>>num5;
sum= num1>+num2+num3+num4+num5;
average=sum/5;
• How about we want to add 100 or 1000 numbers ??
• Therefore, repetition structure offers a better way of
performing those task.
45. REPETITION STRUCTURE
• A programming control structure that allows a
series of instructions to be executed more
than once.
• The similar statement is repeated several
times until the condition are fulfilled.
• There are three types of loop:
for
while
do..while
47. For statement
• General form of for structure:
for(initialize;condition;counter)
Statement block;
• The initialize part is used to initialize any variables that may need to
be initialized. This part is performed just once at the start of the
loop.
• The condition part determines wether the loop execution should
continue.
• If the value of expression is TRUE (non zero), the statement block
will be executed otherwise the loop will be terminated.
• The counter part typically increments or decrements the loop
index.
• This performed every time through the loop iteration.
• This part is used to increment any variable that may need to be
incremented.
48. Example of program
#include<iostream>
using namespace std;
int main()
{
int num, i,sum;
sum=0;
for(i=0;i<5;i++)
{
cout<<“Enter number:”;
cin>>num;
sum=sum+num;
}
cout<<“Total of numbers are:”<<sum;
return 0;
}
50. While statement
• General form:
while (expression)
statement block;
• The first expression evaluated,
• If it is True the statement block is executed
• If it False, the statement block is skipped
• A while structure allow the program to repeat a set of statement as long as the
starting condition remains true. “True” is used in the boolean sense snd so the
condition for loop to continue must evaluate to true or false.
• The program evaluates the condition if it true then the statement inside the braces
are executed.
• The condition is evaluated again.This will continue untill the condition is false and
the program jumps to the next line after the body of the structure.
• If only one statement is used in the while loop then the braces are not required.
51. Example of program
#include<iostream>
using namespace std;
int main()
{
int num, i,sum;
i=0;
sum=0;
while(i<5)
{
cout<<“Enter number:”;
cin>>num;
sum=sum+num;
i++;
}
cout<<“Total of numbers are:”<<sum;
return 0;
}
Output:
Enter number:10
Enter number:2
Enter number:12
Enter number:4
Enter number:2
Total of numbers are:30
53. do....while statement
• General form:
do
{
statement block;
}
while(expression);
• The do part contains the body and is executed as long as
the while condition remains true.
• The difference between these two while structure are while
loop the condition is evaluated first and if it immediately
false, the condition is tested and so guaranteed to be
executed at least once.
54. Example of program
#include<iostream>
using namespace std;
int main()
{
int num, i,sum;
i=0;
sum=0;
do
{
cout<<“Enter number:”;
cin>>num;
sum=sum+num;
i++;
} while(i<5);
cout<<“Total of numbers are:”<<sum;
return 0;
}
Output:
Enter number:5
Enter number:8
Enter number:12
Enter number:3
Enter number:10
Total of numbers are:38
55. continue and break statement
• Two commands that can be included in
looping processes are continue and break.
• When included continue statement in the
body of the loop causes the program to return
immediately to the start of the loop and
ignore any remaining part of the body.
• The break statement causes the program to
immediately exit from the loop and resume at
the next of the progarm.
56. Example of program
(continue)
#include<iostream>
using namespace std;
int main()
{
int num, i,sum;
i=0;
sum=0;
while(i<5)
{
i++;
if(i==3)
continue;
cout<<"Enter number "<<i<<":";
cin>>num;
sum=sum+num;
}
cout<<“Total of numbers are:”<<sum;
return 0;
}
Output:
Enter number 1:10
Enter number 2: 5
Enter number 4:12
Enter number 5:3
Total of numbers are:30
57. Example of program
(break)
#include<iostream>
using namespace std;
int main()
{
int num, i,sum;
i=0;
sum=0;
while(i<5)
{
cout<<“Enter number”;
cin>>num;
sum=sum+num;
i++;
if(i==3)
break;
}
cout<<“Total of numbers are:”<<sum;
return 0;
}
Output:
Enter number:5
Enter number:20
Enter number:10
Total of numbers are:35
58. Difference between the loops
structure
for while do..while
#include<iostream>
using namespace std;
int main()
{
for(i=0;i<3;i++)
{
cout<<“welcome!”;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
i=0;
while(i<3)
{
cout<<“welcome!”;
i++;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
i=0;
do
{
cout<<“welcome!”;
i++;
} while(i<3);
return 0;
}