Assignment 2 PF
Assignment 2 PF
QUESTIONS
The questions listed below need to be answered:
What is an algorithm? How does it differ from program control? Demonstrate the concept of
an algorithm using an example of feeding family.
Define pseudocode and provide a pseudocode representation for computing the overall
grade in a subject, considering assignments, quizzes, exams, and labs.
Explain the concepts of keywords and identifiers, and enumerate various keywords used in
C++.
Explain the purpose of using namespace std, #include, cin>>, cout<<, int main(), return 0,
etc.
ANSWERS
1. WHAT IS AN ALGORITHM? HOW DOES IT DIFFER FROM PROGRAM CONTROL?
DEMONSTRATE THE CONCEPT OF AN ALGORITHM USING AN EXAMPLE OF
FEEDING FAMILY.
For example, a search algorithm takes a search query as input and runs it through a set of
instructions for searching through a database for relevant items to the query. Automation
software acts as another example of algorithms, as automation follows a set of rules to complete
tasks. Many algorithms make up automation software, and they all work to automate a given
process.
Program control, on the other hand, refers to the flow of instructions within a computer program.
It determines the order in which instructions are executed and how the program responds to
different inputs or conditions. While algorithms provide a high-level description of a solution,
program control specifies the details of how the solution is implemented in a programming
language.
1.5 ALGORITHM FOR FEEDING A FAMILY:
The steps involved would be as under, one can represent them using a diagram as well:
Gather Ingredients
Prepare Cooking Utensils
Choose a Recipe
Follow the Recipe Steps
Cook the Meal
Serve the Meal
Enjoy the Meal
2. DEFINE PSEUDOCODE AND PROVIDE A PSEUDOCODE REPRESENTATION FOR
COMPUTING THE OVERALL GRADE IN A SUBJECT, CONSIDERING
ASSIGNMENTS, QUIZZES, EXAMS, AND LABS.
2.1 CODE:
1. Initialize totalScore to 0
2. Input and compute assignmentScore
3. Input and compute quizScore
4. Input and compute examScore
5. Input and compute labScore
6. Input and compute assignmentWeightage
7. Input and compute quizWeightage
8. Input and compute examWeightage
9. Input and compute labWeightage
10. Compute weightedSum as (assignmentScore * assignmentWeightage) + (quizScore *
quizWeightage) + (examScore * examWeightage) + (labScore * labWeightage)
11. Set totalWeightage to assignmentWeightage + quizWeightage + examWeightage +
labWeightage
12. Compute overallGrade as weightedSum / totalWeightage
13. Output overallGrade
3.1 KEYWORDS:
Keywords are reserved words in a programming language that have predefined meanings and
cannot be used as identifiers (variable names, function names, etc.). They convey specific
instructions or represent essential elements of the language.
Keywords are the building blocks of the language's syntax, helping to structure the code and
define its logic.
For example, in C++, keywords include int, if, else, for, while, class, return, and many more.
3.2 IDENTIFIERS:
Identifiers are names given to various program elements such as variables, functions, classes,
etc. They are user-defined and should follow certain rules, unlike keywords.
Identifiers provide a way for programmers to name and reference elements within their code,
making it more readable and understandable.
For example, in C++, identifiers can be names like counter, calculateTotal, myClass, etc.
3.3 DATA TYPES:
int, float, double, char, bool, etc.
CONTROL FLOW:
if, else, switch, case, break, continue, return, etc.
LOOPS:
for, while, do, break, continue, etc.
3.4 FUNCTIONS:
void, main, sizeof, etc.
3.5 CLASSES AND OBJECTS:
class, struct, private, public, new, delete, etc.
3.6 MODIFIERS:
const, static, virtual, mutable, volatile, etc.
Simplifies the use of standard C++ library elements by bringing them into the current scope.
#INCLUDE:
CIN >>:
Reads data from the standard input (e.g., keyboard) into variables during program execution.
COUT <<:
Outputs data to the standard output (e.g., console) during program execution.
INT MAIN():
Defines the main function, serving as the entry point for program execution.
RETURN 0;:
Indicates successful program termination; conventionally used to signal that the program
executed without errors.
4.2 OUTPUT