0% found this document useful (0 votes)
2 views

Lab Manual 3

The document covers programming fundamentals, focusing on conditional constructs and their execution in programming. It provides examples of conditional statements in C++ and outlines several tasks for writing programs that utilize these constructs, such as checking number values, performing arithmetic operations, and determining eligibility based on user input. Additionally, it includes a salary determination task based on gender, years of service, and qualifications.

Uploaded by

adanzahra19
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab Manual 3

The document covers programming fundamentals, focusing on conditional constructs and their execution in programming. It provides examples of conditional statements in C++ and outlines several tasks for writing programs that utilize these constructs, such as checking number values, performing arithmetic operations, and determining eligibility based on user input. Additionally, it includes a salary determination task based on gender, years of service, and qualifications.

Uploaded by

adanzahra19
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PROGRAMMING FUNDAMENTALS

 Learning how conditions can be executed.


 Write a complete program that will use conditional constructs.

Learning how conditions can be executed.

A computer can proceed:


 In sequence
 Selectively (branch): making a choice
 Repetitively (iteratively): looping
Some statements are executed only if certain conditions are met. A condition is
met if it evaluates to true. Following are 3 selection/conditional statements.
PROGRAMMING FUNDAMENTALS

#include <iostream>
using namespace std;

int main() {
cout << "Enter a number: ";
int number;
cin >> number;
int absoluteValue=number;
if (number < 0) {
absoluteValue = -number;
}
cout << "The absolute value of " <<
number << " is " << absoluteValue << endl;
return 0;
}
#include <iostream>
using namespace std;

int main() {
cout << "Enter a number: ";
int number;
cin >> number;

if (number % 2 == 0) {
cout << number << " is even." << endl;
} else {
cout << number << " is odd." << endl;
}

return 0;
}
#include <iostream>
using namespace std;

int main() {
int age;
cout << "Enter your age: ";
cin >> age;

if (age >= 18) {


cout << "You are eligible to vote." <<
endl;
PROGRAMMING FUNDAMENTALS

char citizenship;
cout << "Are you a citizen? (y/n): ";
cin >> citizenship;

if (citizenship == 'y' || citizenship == 'Y')


{
cout << "You can participate in the
election." << endl;
} else { cout << "You need to be a
citizen to participate in the election." << endl;
}
}
else {
cout << "You are not eligible to vote."
<< endl;
}

return 0;
}

Write a complete program that will use conditional constructs.

Task 01: Write a program in which it takes a number from keyboard as an input and if the
number is greater than 100 it prints “The number is greater than hundred”.
Task 02: Write a program in which it takes two numbers from keyboard as input and subtract
larger number from smaller.
Task 03: Write a program which take a number from keyboard and checks the number whether
that number is less than 100 or not if that number is less than 100 than check that is it less than
50 or not.
Task 04: Write a program which takes marks as input and shows the output as follows:
Greater than or equal to 75 : A
Greater than or equal to 60 : B
Greater than or equal to 45 : C
Less than 45 : Fail
PROGRAMMING FUNDAMENTALS

Task 05: Get gender, year of service and qualification of employee as input from keyboard and
determine his/her salary based on following chart.

Gender Year of service Qualification salary


Male >=10 P 15000
>=10 G 12000
<10 P 10000
<10 G 7000
Female >=10 P 12000
>=10 G 10000
<10 P 7000
<10 G 6000

You might also like