Week 2PRG 218Variables and Input and Output OperationsWrite .docxco4spmeley
Week 2
PRG 218
Variables and Input and Output Operations
Write a 70- to 100-word response to the following:
Supporting Activity: Small Program
Create
a small program that:
1)
Prompts the user for a positive integer.
2)
Prints out 0 if the number is ODD or 1 if the number is EVEN.
Did you encounter compiler errors? How did you test your code?
Are there multiple ways to write this program? Explain
.
Supporting Activity: Code Exercise
2
Type
in the code and run any 3 of the "Try It Out" exercises in Ch. 2.
Which exercises did you select? Why? What did you learn?
3
What is the purpose of the document template in an MFC Windows program?
5
Why do you need to be careful, and plan your program structure in advance, when using the Application Wizard?
6
Code up the simple text editor program. Build both debug and release versions, and examine the
types and sizes of the fi les produced in each case.
7
Generate the text editor application several times, trying diff erent project styles from the Application Type in Application Wizard
.
8
Program Input and the Software Design Process" of Programming and Problem Solving with C++: Comprehensive
Overtime Pay Compile Errors
Use
the code in
Appendix B
for this assignment.
Correct
the compile errors to arrive at the following output.
•Sample output:
Enter the Employee Name = Mary
Enter the hours worked = 43
Enter his or her hourly wage = 3.00
Employee Name ............. = Mary
Base Pay .................. = 120
Hours in Overtime ......... = 3
Overtime Pay Amount........ = 13.5
Total Pay.................. = 133.5
Appendix B
Instructions
Overtime Pay Compile Errors
Material
Use the following code to complete your Overtime Pay Compile Errors assignment.
#include
#include
#include
using namespace std;
//Global Declarations of Variables
double iovertime_hours=0, iovertime pay=0, iovertime_extra=0;
int ihours, iwage ;
string cname ;
int main ()
{
//Enter Employee Information
cout << "\n\nEnter the employee name = ";
cin >> cname ;
cout << "Enter the hours worked
= "
cin >> ihours;
cout << "Enter his or her hourly wage = "
cin >> iwage
// Determine if hours are greater than 40
if (ihours < 40)
{
//Do Calculations
iovertime_hours=ihours+40;
iovertime_pay=iwage-1.5 ;
iovertime_extra=iovertime_hours*iovertime_pay;
/ Display Employee Details
cout >> "\n\n";
cout << "Employee Name ............. = ' << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
}
else // Else hours are less than 40 hours
{
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << Base Pay .................. = " << iwage*40 << endl ;
cout << "Hours in Overtime ........
1.History of C Language, Structure of a C program, Statements, Basic Data Types, Variables &Constants, Input & Output statements, Operators and Precedence, Expressions, Simple C programs.
Week 2PRG 218 Variables and Input and Output OperationsWrite.docxmelbruce90096
Week 2
PRG 218 Variables and Input and Output Operations
Write a 70- to 100-word response to the following:
Supporting Activity: Small Program
Create a small program that:
1) Prompts the user for a positive integer.
2) Prints out 0 if the number is ODD or 1 if the number is EVEN.
Did you encounter compiler errors? How did you test your code?
Are there multiple ways to write this program? Explain.
Supporting Activity: Code Exercise
2 Type in the code and run any 3 of the "Try It Out" exercises in Ch. 2.
Which exercises did you select? Why? What did you learn?
3 What is the purpose of the document template in an MFC Windows program?
5 Why do you need to be careful, and plan your program structure in advance, when using the Application Wizard?
6 Code up the simple text editor program. Build both debug and release versions, and examine the types and sizes of the fi les produced in each case.
7 Generate the text editor application several times, trying diff erent project styles from the Application Type in Application Wizard.
8 Program Input and the Software Design Process" of Programming and Problem Solving with C++: Comprehensive
Overtime Pay Compile Errors
Use the code in Appendix B for this assignment.
Correct the compile errors to arrive at the following output.
•Sample output:
Enter the Employee Name = Mary
Enter the hours worked = 43
Enter his or her hourly wage = 3.00
Employee Name ............. = Mary
Base Pay .................. = 120
Hours in Overtime ......... = 3
Overtime Pay Amount........ = 13.5
Total Pay.................. = 133.5
Appendix B
Overtime Pay Compile Errors
Instructions
University of Phoenix Material
Use the following code to complete your Overtime Pay Compile Errors assignment.
#include <io>
#include <string>
#include <iomanip>
using namespace std;
//Global Declarations of Variables
double iovertime_hours=0, iovertime pay=0, iovertime_extra=0;
int ihours, iwage ;
string cname ;
int main ()
{
//Enter Employee Information
cout << "\n\nEnter the employee name = ";
cin >> cname ;
cout << "Enter the hours worked = "
cin >> ihours;
cout << "Enter his or her hourly wage = "
cin >> iwage
// Determine if hours are greater than 40
if (ihours < 40)
{
//Do Calculations
iovertime_hours=ihours+40;
iovertime_pay=iwage-1.5 ;
iovertime_extra=iovertime_hours*iovertime_pay;
/ Display Employee Details
cout >> "\n\n";
cout << "Employee Name ............. = ' << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
}
else // Else hours are less than 40 hours
{
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << Base Pay .......
I am Josh U. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from St. Edward’s University, USA. I have been helping students with their homework for the past 5 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Essentials of Automations: Optimizing FME Workflows with Parameters
Unit 3
1. F1001 PROGRAMMING FUNDAMENTALS
UNIT
3
CONTROL STRUCTURE
Sequential Control Structure
Selection Control Structure
Decision Control Structure
30
2. F1001 PROGRAMMING FUNDAMENTALS
BLOCKS OF CODE
• Every programming language consists of thousand of statements.
• Thus, to simplify the execution of the programming language, all the statements in the programming
language is divided into blocks of code that have specific functions.
• Statement in a block of code is arranged sequentially in a program.
• A block of code is a group of statements that performs one particular task.
• The block is separated in several ways, like curly bracket “{“ and “}”, Begin and End statement and
others.
• Function is a block of code that has been assigned a name.
• Function is used as reference and execution for a block of code.
• Combination of blocks of code will produce a perfect program to be executed in a computer.
• Since the program comes from the different blocks of code, so, the flow needs to be controlled.
• Example of blocks of code:
void welcome ( )
{
BLOCK OF
BLOCK printf (“****************************”);
printf (“********WELCOME **********”); CODE
SEPARATO printf (“****************************”);
R }
PROGRAM FLOW
• Program flow in computer is controlled by the control structure.
• Control structure is a logical structure that controls the flow of instruction to be executed by computer.
• Control structure uses single entry and single exit; meaning it has only one beginning and one ending.
• There are three types of control structures:
1. Sequential control structure
2. Selection / decision control structure
a) If……endif
b) If……else
c) Nested if
3. Looping control structure
a) For
b) While
c) Do……while
31
3. F1001 PROGRAMMING FUNDAMENTALS
Sequential Control Structure
In this control, every step will be executed one by one from top to bottom.
Every box in control structure is a process. Every process is done sequentially.
Format:
Pseudocode:
START
Start
Flowchart Statement A
Statement A
Statement B
Statement B
End
END
Example 1:
Compute the total overtime wages of an employee.
Problem analysis:
Input:
o Hours
o Basic_salary
o OT_rate
Process:
o Overtime equals OT_rate times Hours
o Salary equals Basic_salary plus Overtime
Output:
o Salary
Algorithm:
1. Enter Hours, Basic_salary, OT_rate
2. Calculate overtime using formula:
Overtime = OT_rate * Hours
3. Calculate salary using formula:
Salary = Basic_salary + Overtime
4. Output Salary
32
4. F1001 PROGRAMMING FUNDAMENTALS
Pseudocode:
START
Input Hours, Basic_salary, OT_rate
Overtime = OT_rate * Hours
Salary = Basic_salary + Overtime
Output Salary
END
Flowchart:
START
Input Hours,
Basic_salary, OT_rate
Overtime = OT_rate * Hours
Salary = Basic_salary + Overtime
Output
Salary
END
Example 2:
Problem: Mathematical operation: Get two numbers, then do adding, subtracting, multiplying
and dividing operations.
Problem analysis:
Input:
o number_1, number_2
Process:
o Add 2 numbers:
Sum = number_1 + number_2
o Minus 2 numbers:
Subtract = number_1 – number_2
o Multiply 2 numbers:
33
6. F1001 PROGRAMMING FUNDAMENTALS
Pseudocode:
START
Input number_1, number_2
Sum = number_1 + number_2
Subtract = number_1 - number_2
Multiple = = number_1 * number_2
Divide = number_1 / number_2
Output Sum, Subtract, Multiple, Divide
END
Selection / Decision Control Structure
This type of control structure is usually used in structured programming
This control structure will execute an instruction based on result of a condition or comparison.
A condition will result either TRUE or FALSE.
If the condition result is true, the control program will execute the instruction within the TRUE loop
operation.
Otherwise, it will execute the next instruction or the instruction within the FALSE loop operation.
Example 1:
Condition: A person can obtain a license when he/ she is above 21 years old
Decision: If true then she / he is qualified to have driving license. If not he / she is not qualified to
have a driving license.
Below is a flowchart of control structure:
35
7. F1001 PROGRAMMING FUNDAMENTALS
START
True
Condition Input age
False Statement that will be
executed if condition True
Statement that will be is true If age > 21
executed if condition
is not true False
Output
“Qualified”
Output “Not
Qualified”
END
Type of selection / decision control structure:
1. If……endif
2. If……else
3. Nested if
1. IF…….ENDIF
Rules:
If (condition)
Instruction (do this instruction if condition is true)
Endif
If condition is not true, no instruction will be executed
36
8. F1001 PROGRAMMING FUNDAMENTALS
Pseudocode:
If (condition)
START
True statement
Endif
True
Conditi
Statement
Flowchart:on
False
END
Example 1:
Workers who work on shift 3 will receive additional Bonus RM50, where basic salary is
entered by workers.
Problem analysis:
Input: 1. Shift
2. Basic_salary
Process: Bonus equals RM 50
If Shift equals to 3:
Salary equals Bonus plus Basic_salary
Output: Salary
Algorithm:
1. Enter Basic_salary, Shift
2. Bonus equals to RM 50
3. Check workers Shift
3.1 If Shift equals to 3
Salary= Basic_salary + Bonus
4. Display Salary
37
9. F1001 PROGRAMMING FUNDAMENTALS
Flowchart:
START
Input Shift, Basic_salary
Bonus = 50
True
If Shift =
Salary = Basic_salary + Bonus
3
False
Output Salary
END
Pseudocode:
START
Input Shift, Basic_salary
Bonus = 50
If (Shift ==3)
Salary = Basic_salary + Bonus
End if
Output Salary
END
38
10. F1001 PROGRAMMING FUNDAMENTALS
2. IF…….ELSE type
A selection of control structure is used to select between two options
Pseudocode:
Rules:
If (condition)
If (condition)
True statement
True statement
Else
Else
False statement
False statement
Endif
Endif
Flowchart:
START
False True
Conditi
on
Statement 2 Statement 1
END
Example 1:
o Prepare a problem analysis, algorithm, flowchart and pseudocode to identify whether a
student is qualified to further her / his studies in any local university using his / her SPM
grade equal to 1.
o Problem analysis:
Input: Grade
Process: If Grade is equal to 1
Output “Qualified to further study”.
If not
Output “Not qualified to further study”.
Output: Display message qualified or not
39
11. F1001 PROGRAMMING FUNDAMENTALS
o Algorithm:
1. Enter Grade
2. Check Grade
1.1 If Grade = 1
1.1.1 Output “Qualified to further study”
1.2 If not
1.2.1 Output “Not qualified to further study”
o Flowchart:
START
Input Grade
False True
If
Grade
Output “Not qualified Output “Qualified
to further study” to further study”
END
o Pseudocode:
START
Input Grade
If (Grade==1)
Output “Qualified to further study”
Else
Output “Not qualified to further study”
Endif
END
40
12. F1001 PROGRAMMING FUNDAMENTALS
Example 2:
o Problem:
Prepare the problem analysis, algorithm, flowchart and pseudocode to find
subtraction between two numbers that users enter.
o Problem analysis:
Input: num1, num2
Process: If num1 greater than num2
Result = num1 – num2
If not
Result = num2 – num1
Output: Result
o Algorithm:
1. Enter num1, num2
2. Compare the 2 numbers
2.1 If num1 greater than num2
2.1.1 Result = num1 – num2
2.2 If not
2.2.1 Result = num2 – num1
3. Display Result
o Flowchart:
START
Input num1, num2
False True
If num1 >
num2
Result = num2 – num1 Result = num1 – num2
Output Result
END 41
13. F1001 PROGRAMMING FUNDAMENTALS
o Pseudocode:
START
Input num1, num2
If num1 > num2
Result = num1 – num2
Else
Result = num2 – num1
Endif
Output Result
END
3. NESTED IF
There are 3 types:
1. Type 1:
If (condition1)
If (condition2)
If (condition3)
True statement
Endif
Endif
Endif
2. Type 2:
If (condition1)
If (condition2)
If (condition3)
Statement that will be executed if condition1, condition2
and condition3 are true
Else
Statement that will be executed if condition1, and
condition2 are true but condition2 is false
Endif
42
14. F1001 PROGRAMMING FUNDAMENTALS
Else
Statement that will be executed if condition1 is true but condition2
and condition3 is false
Endif
Else
Statement that will be executed if condition1 is false
Endif
3. Type 3
If (condition1)
Statement that will be executed if condition 1 is true
Else
If (condition 2)
Statement that will be executed if condition2 is true but
condition1 is false
Else
If (condition3)
Statement that will be executed if condition3 is true
but condition1 and condition2 are false
Else
Statement that will be executed if condition1,
condition2 and condition3 are false
Endif
Endif
End if
Example Type 1:
o Problem:
To determine whether a candidate is qualified or not to get a scholarship based on his /
her study years, guardian’s salary and student CGPA. If the study year is more than 1,
student’s CGPA is not less than 3.00 and guardian’s salary is below than RM500,
student will be considered for a scholarship.
o Problem analysis:
Input: CGPA, Year, Salary.
Process:
43
15. F1001 PROGRAMMING FUNDAMENTALS
1. Check if the student application’s can be considered or not for a scholarship.
1.1 If Year greater than 1
1.1.1 If CGPA greater than or equal to 3.00
1.1.1.1 If Salary is less than or equal to RM500
Output “Your application is under consideration”.
Output: Student status
o Algorithm:
1. Enter CGPA, Salary and Year
2. Check if the student application’s can be considered for a scholarship
2.11 If year > 1
2.1.1 If CGPA >= 3.00
2.1.1.1 If salary <= RM500
Output “Your application is under consideration”
3.1 Display status
o Flowchart:
START
Input Year, CGPA, Salary
False True
If Year > 1
False If CGPA True
>= 3.00
Output “Your
False If Salary True
application is under
<= 500
consideration”
END
44
16. F1001 PROGRAMMING FUNDAMENTALS
o Pseudocode:
START
Input Year, CGPA, Salary
If Year >1
If CGPA >= 3.00
If Salary <= RM500
Output “Your application is under consideration”
Endif
Endif
Endif
END
Example Type 2:
o Problem:
To determine whether a candidate is qualified or not to get a scholarship based on his /
her study years, guardian’s salary and student CGPA. If the study year is more than 1,
student’s CGPA is not less than 3.00 and guardian’s salary is below than RM500, student
will be considered for a scholarship. If the student is not qualified the message “Not
success” will be displayed.
o Problem analysis:
Input: CGPA, Year, Salary
Process:
1. Check if a student can be considered for a scholarship
1.1 If Year > 1
1.1.1 If CGPA >= 3.00
1.1.1.1 If Gaji <= 500
Output “You application is under consideration”
1.1.1.2 If not
Output “Not success”
1.1.2 If not
Output “Not success”
1.2 If not
Output “Not success”
Output: Student status
45
17. F1001 PROGRAMMING FUNDAMENTALS
o Algorithm:
1. Enter CGPA, Year, Salary
2. Check if a student can be considered for a scholarship
2.1 If Year > 1
2.1.1 If CGPA >= 3.00
2.1.1.1 If Salary <= RM500
Output “Your application is under consideration”.
2.1.1.2 If not
Output “Not success”
2.1.2 If not
Output “Not success”
2.2 If not
Output “Not success”
3. Display status
o Flowchart:
START
Input Year, CGPA, Salary
False True
If Year > 1
Output “Not False If CGPA True
success” >= 3.00
Output “Your
Output “Not False If Salary True
application is under
success” <= 500
consideration”
Output “Not
success”
END
46
18. F1001 PROGRAMMING FUNDAMENTALS
o Pseudocode:
Input CGPA, Salary, Year
If (year > 1)
If (CGPA >= 3.00)
If (salary <= RM500)
Output “Your application is under consideration”
Else
Output ”Not success”
Endif
Else
Output ”Not success”
Endif
Else
Output ”Not success”
Endif
Example Type 3:
o Problem: Education status is determined based on the GPA achievement under the
following scheme:
GPA Status
3.50-4.00 Dean List
2.00-3.49 Pass
1.80-1.99 Conditional Pass
0.00-1.79 Fail
o Problem analysis:
Input: GPA
Process:
1. If (GPA < 0.00 AND GPA > 4.00)
Output “Invalid data”
2. If not
2.1 If (GPA >=3.5 AND GPA <= 4.00)
Output “Dean List”
2.2 If not
2.2.1 If (GPA >= 2.00 AND GPA < 3.50)
Output “Pass”
2.2.2 If not
2.2.2.1 If (GPA >= 1.80 AND GPA< 2.00)
Output “Conditional Pass”
2.2.2.2 If not
Output “Fail”
Output: Student education status
47
19. F1001 PROGRAMMING FUNDAMENTALS
o Algorithm:
1. Enter student GPA
2. Compare student’s GPA to determine his/ her education status.
2.1 If (GPA < 0.00 AND GPA > 4.00)
Output “Invalid data”
2.2 If not
2.2.1 If (GPA >=3.50 AND GPA <= 4.00)
Output “Dean List”
2.2.2 If not
2.2.2.1 If (GPA >= 2.00 AND GPA < 3.50)
Output “Pass”
2.2.2.2 If not
2.2.2.2.1If (GPA >= 1.80 AND GPA < 2.00)
Output “Conditional Pass”
2.2.2.2.2If not
Output “Fail”
3. Print status
o Flowchart:
48
20. F1001 PROGRAMMING FUNDAMENTALS
START
Input GPA
True False
If GPA < 0.00
&& GPA > 4.00
True False
If GPA >= 3.50 &&
Output “Invalid GPA <= 4.00
data”
Output “Dean True False
If GPA >= 2.00 &&
List” GPA < 3.50
True False
If GPA >= 1.80 &&
Output “Pass” GPA < 2.00
Output
Output “Fail”
“Conditional Pass”
END
o Pseudocode:
START
Input GPA
If ((GPA < 0.00) AND (GPA > 4.00))
Output "Invalid Data"
Else
If ((GPA >= 3.50) AND (GPA <= 4.00))
Output "Dean List"
Else
If ((GPA >=2.00) AND (GPA < 3.50))
Output "Pass"
Else
49
21. F1001 PROGRAMMING FUNDAMENTALS
If ((GPA >= 1.80) AND (GPA < 2.00))
Output "Conditional Pass”
Else
Output "Fail"
Endif
Endif
Endif
Endif
END
Usage of Logical Operator:
Symbol Symbol Example Result Description
(Pseudocode) (C Language)
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
o From the above table, the logical operator are AND, OR and NOT.
o Example using of AND operator:
If ((a < b) && (c > d))
printf(“Print a and c”);
o If condition (a < b) is true AND condition (c > d) is true then “Print a and c” will be
displayed. If one of the condition is not true then “Print a and c” will not be displayed.
o Example usage of OR operator:
If ((sales > 5000) || (hoursworked> 81))
bonus = 500;
else
bonus = 0;
50
22. F1001 PROGRAMMING FUNDAMENTALS
o 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 still be given
as bonus.
o If both conditions are false, then bonus will not be given.
Looping Control 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 conditions are fulfilled.
Three are three types of loop:
o For
o While
o Do…while
For While Do…while
For (initialize; condition; counter) While (condition) Do
True statement if condition is True statement True statement
fulfilled Endwhile While (condition)
Endfor
o Initialize value: a value to start a loop.
o Counter: to increase or decrease the initialize value.
o Rules for the condition:
- If the condition is true / fulfilled, the process will be performed.
- Then, the program loops back and recheck the condition, if the condition is true /
fulfilled, repeat the process.
- When the condition is false, then exit the loop.
Format for Do …… while loop:
Format for the For and While loops:
START START
Initialize Initialize
Statement A
Test False
END True
condition Test
condition
True
False
Example of loops usage: A
Statement
END
51
23. F1001 PROGRAMMING FUNDAMENTALS
o Problem: Prepare the problem analysis, algorithm, flowchart and pseudocode for the average of 5
numbers. Data will be entered by user.
o Problem analysis:
Input: 5 numbers
Process: The process of adding numbers will repeat until the condition to exit the loop is met.
Output: Average of 5 numbers
o Algorithm:
1. Initialize Counter=0; Average = 0; Total = 0
2. Input number
3. Add Total using formula:
Total = Total + number
4. Add Counter using formula:
Counter = Counter + 1
5. Compare whether Counter is greater than 5
If yes , go to step 6
If not, go to step 2
6. Calculate Average of numbers using formula;
Average = Total/5
7. Display Average
o Pseudocode:
For loop While loop Do…while loop
START START START
no = 0 no = 0 no = 0
Total = 0 Total = 0 Total = 0
Avg = 0 Avg = 0 Avg = 0
For (no=0; no<=5; no++) While (no <= 5) Do {
Input Num Input Num Input Num
Total = Total + Num Total = Total + Num Total = Total + Num
Endfor no = no + 1 no = no + 1
Avg = Total/5 Endwhile } While (no <= 5)
Output Avg Avg = Total/5 Avg = Total/5
END Output Avg Output Avg
END END
o Flowchart for For and While loops:
52
24. F1001 PROGRAMMING FUNDAMENTALS
START
no = 0
Total = 0
Avg = 0
For / False
While no Avg = Total/5
True
Input Num Output Avg
Total = Total + Num END
no = no + 1
o Flowchart for Do……while loop:
53
25. F1001 PROGRAMMING FUNDAMENTALS
START
Note:
no: a variable to control loop
no = 0 structure whether to continue or
exit from the loop
Total= 0
no + 1: a counter and it is very
Avg = 0 important. Without a counter, the
loop will be infinite
Input Num
Total = Total + Num: a variable to
compute the value
Total = Total + Num
no = no + 1
True False
no <= 5 Avg = Total/5
Output Avg
END
o Example: To compute salary of 20 employees
Algorithm for For and While loops:
1. Initialize Counter = 0, Salary = 0;
2. Compare whether Counter is greater than 20 or not
If yes , out from the loop
If not , go to step 3
3. Enter Basic_salary, Claim, O_time
4. Calculate EPF:
EPF = Basic_salary * 0.09
5. Calculate Salary using this formula:
Salary = Basic_salary + Claim + O_time – EPF
6. Display Salary
7. Add Counter using the formula:
Flowchart for For and While loops:
Counter = Counter + 1
8. Back to step 2
54
26. F1001 PROGRAMMING FUNDAMENTALS
START
no = 0
Salary = 0
For / False
END
While no
True
Input
Basic_salary,
Claim, O_time
EPF = Basic_salary * 0.09
Salary = Basic_salary + Claim + O_time – EPF
Output Salary
no = no + 1
Pseudocode for For loop:
START
no = 0
Salary = 0
For (no = 0, no <=20, no ++)
Input Basic_salary, Claim, O_time
EPF = Basic_salary * 0.09
Salary = Basic_salary + Claim + O_time – EPF
Output Salary
Endfor
END
Pseudocode for While loop:
55
27. F1001 PROGRAMMING FUNDAMENTALS
START
no = 0
Salary = 0
While no <=20
Input Basic_salary, Claim, O_time
EPF = Basic_salary * 0.09
Gaji = Basic_salary + Claim + O_time – EPF
Output Salary
no = no + 1
Endwhile
END
Algorithm for Do……while loop:
1. Initialize Counter = 0, Salary = 0;
2. Input Basic_salary, Claim, O_time
3. Calculate EPF
EPF = Basic_salary * 0.09
4. Calculate Salary using this formula:
Salary = Basic_salary + Claim + O_time – EPF
5. Add Counter using this formula:
Counter = Counter + 1
6. Compare whether the Counter is greater than 20 or not
If yes , out of loop
If not, go to step 2
7. Display Salary
Flowchart for Do…..while loop:
56
28. F1001 PROGRAMMING FUNDAMENTALS
START
no = 0
Salary = 0
Input
Basic_salary,
Claim, O_time
EPF = Basic_salary * 0.09
Salary = Basic_salary + Claim + O_time – EPF
Output
Salary
no = no + 1
True False
no <= 5 END
Pseudocode for Do…..while loop:
START
no = 0
Salary = 0
Do
{
Input Basic_salary, Claim, O_time
EPF = Basic_salary * 0.09
Salary = Basic_salary + Claim + O_time – EPF
Output Salary
no = no + 1
} While (no <= 20)
o Dummy Data or Sentinel Value
END
57
29. F1001 PROGRAMMING FUNDAMENTALS
- Value used to end the program. Dummy data must be different from the data
to be entered.
- Example:
START
Input name
While name != “XXX”
Dummy data
Output name
Input mark
Output mark
Input name
Endwhile
END
58