C++ Assignment
C++ Assignment
problem.
Loan Approval System
#include <iostream>
int main()
double salary;
int creditScore;
} else {
cout << "Sorry, your loan is rejected due to insufficient salary or low
credit score." << endl;
return 0;
}
Online Shopping Discount
#include <iostream>
int main() {
cout << "Enter your total purchase amount (in PKR): ";
} else {
cout << "Your total discount is: " << discount << " PKR" << endl;
cout << "Final price after discount: " << finalPrice << " PKR" << endl;
return 0;
}
Weather Suggestion System
#include <iostream>
int main() {
double temperature;
} else {
return 0;
}
Bus Fare Calculation
#include <iostream>
int main() {
int age;
int fare;
if (age < 5) {
} else {
cout << "Your bus fare is: " << fare << " PKR" << endl;
return 0;
}
Qno:03 Use Nested if to write C++ code for the
following problem.
Password Strength Checker
#include <iostream>
int main() {
string password;
if (password.length() >= 8) {
if (isupper(ch)) {
hasUpper = true;
if (isdigit(ch)) {
hasDigit = true;
if (hasUpper) {
if (hasDigit) {
cout << "Strong Password" << endl;
} else {
cout << "Weak Password (Must contain at least one digit)" <<
endl;
} else {
} else {
cout << "Weak Password (Must be at least 8 characters long)" << endl;
return 0;
}
Scholarship Eligibility
#include <iostream>
int main() {
} else {
cout << "Sorry, you are not eligible for a scholarship." << endl;
} else {
cout << "Sorry, you are not eligible for a scholarship." << endl;
} else {
cout << "Sorry, you are not eligible for a scholarship." << endl;
return 0;
}
Library Fine System
#include <iostream>
int main() {
int overdueDays;
int fine = 0;
cout << "Enter the number of days the book is overdue: ";
cout << "Total fine: " << fine << " PKR" << endl;
return 0;
}
Qno4: Use Switch Statement to write C++ code for the
following problem.
#include <iostream>
int main() {
int choice;
switch (choice) {
case 1:
cout << "You selected Burger. Price: 300 PKR" << endl;
break;
case 2:
cout << "You selected Pizza. Price: 500 PKR" << endl;
break;
case 3:
cout << "You selected Pasta. Price: 400 PKR" << endl;
break;
case 4:
cout << "You selected Biryani. Price: 250 PKR" << endl;
break;
case 5:
break;
default:
cout << "Invalid choice! Please select a valid option (1-5)." << endl;
return 0;
}
Calculator
#include <iostream>
int main() {
char op;
switch (op) {
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
if (num2 != 0)
else
break;
case '%':
if (static_cast<int>(num2) != 0)
else
break;
default:
return 0;
}
Car Gear System
#include <iostream>
int main() {
int gear;
switch (gear) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
case 5:
break;
default:
cout << "Invalid gear! Please enter a number between 0 and 5." <<
endl;
return 0;
}
Qno5: Use For loop to write C++ code for the following problem.
int main() {
int sum = 0;
sum += i;
cout << "The sum of even numbers between 2 and 20 is: " << sum <<
endl;
return 0;
}
Star Pyramid Pattern
#include <iostream>
int main() {
int rows;
// Print stars
return 0;
}
Fibonacci Series
#include <iostream>
int main() {
second = next;
return 0;