0% found this document useful (0 votes)
38 views3 pages

Midtem D

The document is the midterm examination for the Programming Fundamentals course at the Islamia University of Bahawalpur. It contains 4 questions assessing different programming concepts. Question 1 asks to write a program to calculate the sum of first n natural numbers. Question 2 asks to write a program to count the number of alphabets in a word and replace alphabets between A-K with Z. Question 3 asks to write a program to check user eligibility for different academic programs based on age and GPA criteria. Question 4 asks to write functions to analyze weather data from a text file containing temperature, humidity, wind speed, and sun radiation values over 8 days.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

Midtem D

The document is the midterm examination for the Programming Fundamentals course at the Islamia University of Bahawalpur. It contains 4 questions assessing different programming concepts. Question 1 asks to write a program to calculate the sum of first n natural numbers. Question 2 asks to write a program to count the number of alphabets in a word and replace alphabets between A-K with Z. Question 3 asks to write a program to check user eligibility for different academic programs based on age and GPA criteria. Question 4 asks to write functions to analyze weather data from a text file containing temperature, humidity, wind speed, and sun radiation values over 8 days.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

The Islamia University of Bahawalpur

Department of Electronic Engineering

Midterm examination, Fall-23 Max marks: 25

Programming Fundamentals (Comp – 01315) Time allowed:3 Hrs

Session 2022-26, 3rd semester Instructor: Abid Javed

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>

using namespace std;

int main() {

int n;

cout << "Enter the value of n: ";


2
Q1 cin >> n;
(3)
int sum = 0;

for (int i = 1; i <= n; ++i) {

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;

cout << "Enter a word: ";


cin >> word;

int numAlphabets = 0;
for (int i = 0; i < word.length(); ++i) {

if ('A' <= word[i] && word[i] <= 'Z') {


numAlphabets++;
}
}
cout << "The number of alphabets in the word is: " << numAlphabets << endl;

for (int i = 0; i < word.length(); ++i) {


if ('A' <= word[i] && word[i] <= 'K') {

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>

using namespace std;

int main() {

int age;

float gpa;

string discipline;

cout << "Enter your age: ";

cin >> age;

cout << "Enter your GPA: ";

cin >> gpa;

cout << "Enter the discipline (BS, MS, PhD, Post Doc): ";
cin >> discipline;

bool eligible = false;

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;

Write a program to meet the following task;


You are provided with a text file in .txt format. It contains data about weather of Bahawalpur. Each row
represents a day. There are 8 rows so the file contains data of eight days. There are 04 columns.
Col-1 shows the average temperature of Bahawalpur on that day
Col-2 shows the average humidity in Bahawalpur on that day
Col-3 shows the average wind speed in Bahawalpur on that day 2
Q4
Col-4 shows the average sun radiations in Bahawalpur on that day (12)

You have to write three functions for the following tasks.


a) Display the average value of temperature in 8 days.
b) Display the day on which humidity was maximum and also display the value of humidity.
c) Display the day on which wind speed was (>5 km/hr) and sun radiations were (>50).
*** Bonus points will be given if you save the functions in header file and use it in your main program.
---END---

You might also like