PF Assignment No. 1
PF Assignment No. 1
ASSIGNMENT NO. 1
PROGRAMING FUNDANETAL
Code:
#include <iostream>
int main()
int age; // declare an integer variable age to store the user's age
cin >> age; // prompt the user to enter their age and read it into the variable age
cout << "You may work anywhere" << endl; // print message indicating that the employee may work anywhere
cout << "You can only work in urban areas" << endl; // print message indicating that the employee can only work in
urban areas
// if the age is not within the specified range, print an error message
else
cout << "ERROR" << endl; // print message indicating that the input age is invalid
return 0;
}
Question #2: Write a C++ program that ask user to enter marks and print the corresponding grade. THE SUPERIOR
UNIVERSITY LAHORE (Faisalabad Campus) Assignment_01 (BSSE/BSIT) Faculty of Computer Science and Information
Technology Subject: Programming Fundamentals Instructor: Mr. Ch. Ahmad Bilal Total marks: 30 Instructor:
Muhammad Hassan Total Marks: 50 Using following rules for grading system? a. Below 25 - F b. 25 to 45 - E c. 45 to 50
- D d. 50 to 60 - C e. 60 to 80 - B f. Above 80 - A Ask user to enter marks and print the corresponding grade.
Code:
#include <iostream>
int main()
int marks; // declare an integer variable marks to store the user's marks
cout << "Grade: F" << endl; // print message indicating the corresponding grade is F
cout << "Grade: E" << endl; // print message indicating the corresponding grade is E
}
cout << "Grade: D" << endl; // print message indicating the corresponding grade is D
cout << "Grade: C" << endl; // print message indicating the corresponding grade is C
cout << "Grade: B" << endl; // print message indicating the corresponding grade is B
cout << "Grade: A" << endl; // print message indicating the corresponding grade is A
else
cout << "Invalid marks entered." << endl; // print message indicating that the input marks is invalid
return 0;
}
Question #3: Write a C++ program that input the age of three peoples and determine oldest and youngest among
them?
Code:
#include <iostream>
int main()
cout << "The oldest person is " << age1 << " years old." << endl;
}
cout << "The oldest person is " << age2 << " years old." << endl;
else
cout << "The oldest person is " << age3 << " years old." << endl;
cout << "The youngest person is " << age1 << " years old." << endl;
cout << "The youngest person is " << age2 << " years old." << endl;
else
cout << "The youngest person is " << age3 << " years old." << endl;
return 0;
}
Question #4: Write a C++ program to calculate area of the circle if the radius is greater than 0 using goto statement.?
Code:
#include <iostream>
#include <cmath>
int main()
input:
cout << "Enter the radius of the circle: "; // Prompt the user to enter the radius
cout << "Radius should be greater than 0." << endl; // Output an error message if the radius is invalid
goto input; // Use goto statement to jump back to the input label and prompt the user again for a valid radius
area = M_PI * pow(radius, 2); // Calculate the area of the circle using the formula
cout << "The area of the circle is " << area << endl; // Output the calculated area of the circle
return 0;
Question #5: Write a C++ program in which a user enters a number, and the program will find the Even and odd
number. Your program should only accept integers of length 2 or higher and should ask the user to re-enter a value if
the value containing total numbers of integers less than 2. The program with goto statement?
Code:
#include <iostream>
int main()
int num;
input:
cout << "Enter a number (must be at least 2 digits long): "; // Prompt the user to enter a number
if(num < 10) // Check if the number entered by the user has less than 2 digits
cout << "Number must be at least 2 digits long." << endl; // Output an error message if the number has less than 2
digits
goto input; // Use goto statement to jump back to the input label and prompt the user again for a valid number
}
if(num % 2 == 0) // Check if the number is even
cout << "The number " << num << " is even." << endl; // Output a message indicating that the number is even
cout << "The number " << num << " is odd." << endl; // Output a message indicating that the number is odd
return 0;
Question #6: Write a C++ program to find the roots of a quadratic equation ax2 + bx + c = 0?
Code:
#include <iostream>
#include <cmath>
int main() {
/* Calculate determinant */
if(determinant >= 0)
else {
real= -b/(2*a);
cout << "Square roots are " << real << "+" << imag << "i , "
return 0;