Document 1
Document 1
Class: BS AI
Student ID: 0000947237
Submitted To: Mam Yusra
QUESTION 1
Write a C++ program to find maximum between two numbers using
switch case.
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"enter two numbers:";
cin>>a>>b;
switch (a>b) {
case 1:
cout<<"maximum number is:"<<a<<endl;
break;
case 0:
switch (b>a){
case 1:
cout<<"maximum number is"<<b<<endl;
break;
case 0:
cout<<"both numbers are
equal"<<endl;
break;
}
break;
}
return 0;
}
QUESTION 2
Write a C++ program to check whether a number is divisible by 5 and 11
or not.
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"enter the number:";
cin>>num;
if(num%5==0 && num%11==0){
cout<<num<<"is divisible by both 5 and 11"<<endl;
}else{
cout<<num<<"is not devisible by both 5 and 11"<<endl;
}
return 0;
}
QUESTION 3
#include<iostream>
using namespace std;
int main()
{
float angle1,angle2,angle3;
cout<<"enter first angle of the triangle";
cin>>angle1;
cout<<"enter the second angle of the triangle";
cin>>angle2;
cout<<"enter the third angle of the triangle";
cin>>angle3;
if(( angle1+angle2+angle3==180)&& angle1>0 &&angle2>0
&&angle3>0) {
cout<<"the triangle is valid:"<<endl;
}else{
cout<<"the triangle is not valid"<<endl;
}
return 0;
}
QUESTION 4
Write a C++ program to input basic salary of an employee and calculate
its Gross salary according to following: using if -else statement
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary <= 20000 : HRA = 25%, DA = 90%
Basic Salary > 20000 : HRA = 30%, DA = 95%
#include <iostream>
using namespace std;
int main() {
float basicSalary, hra, da, grossSalary;
return 0;
}
QUESTION 5
Write a program that allows the user to enter any character through the
keyboard and determines, whether it is a capital letter, small letter, a digit
number or a special symbol.
#include <iostream>
using namespace std;
int main() {
char ch;
return 0;
}
QUESTION 6
Write a C++ program to check whether a number is palindrome or not.
#include <iostream>
using namespace std;
int main() {
int num, originalNum, reversedNum = 0, remainder;
originalNum = num;
return 0;
}
QUESTION 7
Write a program that inputs two numbers, swaps these values without
using third variable and display them
#include <iostream>
using namespace std;
int main() {
int a, b;
return 0;
}
QUESTION 8
Write a program that inputs a five digit number as input and reverse the
number. For example if the user enter 92174, it displays 47129 .
#include <iostream>
using namespace std;
int main() {
int a, b;
return 0;
}
QUESTION 9
What types of errors can occur while writing a computer program?? How
these errors can be removed in C/C++? Explain the debugging procedure
in C/C++.
a. Syntax Errors
Examples:
How to fix:
Examples
How to fix:
c. Logical Errors
Examples:
How to fix:
Use of Tools:
Memory checkers (e.g., Valgrind for detecting memory leaks and invalid
access).
bash
CopyEdit
gcc -g program.c -o program
1.
Start debugger:
bash
CopyEdit
gdb ./program
2.
Set Breakpoints:
Use step (s) and next (n) to execute line by line and examine
logic.
Watch Variables:
1. Code Editing
Syntax highlighting
Auto-completion
Code formatting
Bracket matching
Error highlighting
2. Compilation
3. Running Programs
4. Debugging Tools
Breakpoints
Step-by-step execution
Watch expressions
5. Project Management
6. Other Tools
Build automation
Since you didn’t specify the IDE you're using, I’ll describe
Code::Blocks and Visual Studio Code (VS Code) — two
common IDEs used in C/C++ courses. Let me know if you're
using a different one.
Key Features:
How it helps:
Key Features:
How it helps:
Highly customizable.