allama Iqbal International University
Assignment :1
Subject : Computer programing 3504
Sunmitted by :
Mian Abd ur Rehman Ijaz
user id: 0000955057
Submitted To:
Mam Yusra
Topic:
c ++ programs
Class :
BS Artificial Intelligence
program 1
take two inputs and give max number output:
program 2
check if the number is divisible by 5 and 11
program 3
check if a triangle is valid or not:
program 4
take basic value from a user and give gross salary
program 5
check the value is a digit or alpabet
program 6
find the input value is a palindorme or not
program 7
swap the values without using third variable
program 8
reverse the input 5 digits
Question 9
Types of Errors in C/C++:
Syntax Errors:
These occur when the code violates the grammatical rules of the language. Common examples include
missing semicolons, incorrect braces, or misspelled keywords.Example: int main() { cout << "Hello,
World!" } (missing semicolon).
Logical Errors:
These occur when the code runs without crashing, but the output is incorrect due to a flaw in the
program's logic. These are often hard to detect since the program runs.Example: A program that
calculates the average but divides by the wrong number.
Runtime Errors:
These happen during the execution of the program, often due to invalid operations like dividing by zero or
accessing invalid memory.Example: int x = 10 / 0; causes a division by zero runtime error.
Debugging in C/C++:
IDE/Debugger Tools:Integrated Development Environments (IDEs), such as Visual Studio or
Code::Blocks, typically offer built-in debuggers that let you step through code, set breakpoints, and
inspect variables.
GDB: The GNU Debugger (GDB) is a powerful tool for debugging C/C++ programs. You can compile
the code with debugging information (g++ -g) and then run it in GDB to find and fix issues cout
Statements: Inserting cout statements at key points in the program can help trace the flow and check the
values of variables
Question 10
Role of an IDE:
Helps Write, Edit, Compile, and Debug Code:
IDEs make coding more efficient by offering tools that streamline the entire development process. They
provide code editing features like auto-completion, syntax highlighting, and refactoring tools.
Examples:
Dev C++: A lightweight IDE popular for C/C++ development.
Code::Blocks: A free, open-source IDE that offers flexibility and support for multiple compilers.
Visual Studio: A powerful IDE, especially for larger C++ projects, with robust debugging and profiling
tools.
Features:
Syntax Highlighting: Makes it easier to identify errors and understand code structure.
Auto-Completion: Helps speed up coding and reduce errors by suggesting code completions.
Debugging Tools: IDEs provide integrated debuggers for setting breakpoints and inspecting variable
values.
Project Management: Helps manage large projects with multiple files and dependencies.