














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The different types of errors in C++ programming, including syntax, runtime, linker, logical, and semantic errors. It also provides examples and pseudocode for algorithms and flowcharts to convert length units and determine student grades and quadratic equation roots. The document concludes with decision structures using if-then-else statements.
Typology: Cheat Sheet
1 / 22
This page cannot be seen from the preview
Don't miss anything!















Errors in C++
Example Syntax Error void main() { int x = 10; int y = 15; cout<<x<<y //semicolon missed }
Run Time Error Runtime errors occur when a program with no syntax errors asks the computer to do something that the computer is unable to reliably do.
Linker Errors After compilation different object files are linked with main’s object, errors generated when the executable of the program cannot be generated
Example Linker Error void Main() // Here Main() should be main() { int a = 10; cout << a; }
Semantic Error Semantic error occurs when the statements written in the program are not meaningful to the compiler Example: void main() { int a, b, c; a + b = c; //semantic error }
Pseudocode: Input the length in feet (lft) Calculate the length in centimeter (lcm) by multiplying feet with 30 Print length in centimeter (lcm) Algorithm: Flowchart: Step 1: Input lft Step 2: lcm lft x 30 Step 3: Print lcm START Input lft Print lcm STOP lcm lft x 30 13
Example 2 Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks Pseudocode: Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print “FAIL” else Print “PASS” 14
Example 3 Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation (ax 2
Pseudocode: Input the coefficients (a,b,c) of the quadratic equation Calculate d Calculate x1 Flowchart: Calculate x Print x1 and x Algorithm: Step 1: Input a, b, c Step 2: d sqrt(bxb – 4xaxc) Step 3: x1 (- b+d) / (2xa) Step 4: x2 (- b-d) / (2xa) Step 4: Print x1, x START Input a, b, c STOP X 2 (– b – d ) / (2 x a ) x 1 (– b + d ) / (2 x a ) d sqrt( b x b – 4 x a x c ) Print x 1, x 2 17
Example 4 Write an algorithm that reads two values, determines the largest value and prints largest value with an identifying message 19
Algorithm: Flowchart 20