Professional Documents
Culture Documents
CLO
Sr. Questions (D)
Marks
Write a program to find the sum of first n natural numbers. Positive integers such as 1,2,3…. n is
known as natural numbers. Ask user to enter value of n.
#include <iostream>
int main() {
int n;
sum=sum + i;
cout << "The sum of first " << n << " natural numbers is: " << sum << endl;
return 0;
}
2
Q2 Write a program to meet the following task;
(3)
a) Ask user to enter a word. Display no. of alphabets in the word.
b) If the alphabets in that word are between “A to K” then replace those alphabets with “Z”
and display that new word.
#include <iostream>
using namespace std;
int main() {
string word;
int numAlphabets = 0;
for (int i = 0; i < word.length(); ++i) {
word[i] = 'Z';
}
}
cout << "The new word after replacement is: " << word << endl;
return 0;
}
2
Q3 Write a program to meet the following task;
(7)
Spring 2024 admissions are open in university. Students want to take admission in different
programs. Following rules must be followed.
BS/BSc.: Age (18 to 24) Minimum GPA (≥2.8)
MS/MSc.: Age (22 to 28) Minimum GPA (≥3.2)
PhD: Age (24 to 50) Minimum GPA (≥3.5)
Post Doc: Age (30 to 50) Minimum GPA (≥3.7)
The requirements for your program are as follows:
a) Ask Age & Minimum GPA of the user.
b) Ask user in which discipline he/she wants to apply.
c) Display that the user is “eligible” or “not eligible” in his/her selected discipline.
#include <iostream>
int main() {
int age;
float gpa;
string discipline;
cout << "Enter the discipline (BS, MS, PhD, Post Doc): ";
cin >> discipline;
if (discipline == "BS" && age >= 18 && age <= 24 && gpa >= 2.8) {
eligible = true;
} else if (discipline == "MS" && age >= 22 && age <= 28 && gpa >= 3.2) {
eligible = true;
} else if (discipline == "PhD" && age >= 24 && age <= 50 && gpa >= 3.5) {
eligible = true;
} else if (discipline == "Post Doc" && age >= 30 && age <= 50 && gpa >= 3.7) {
eligible = true;
cout << "You are " << (eligible ? "eligible" : "not eligible") << " in your selected discipline." << endl;
return 0;