0% found this document useful (0 votes)
2 views4 pages

Assignment 3

The document contains programming assignments for the Department of Information Security at the Islamia University of Bahawalpur, focusing on C++ and C programming fundamentals. It includes various examples of programs using if statements, if-else structures, and switch-case statements to perform calculations and display outputs based on user input. The assignments aim to enhance students' understanding of basic programming concepts and conditional logic.

Uploaded by

lostttbird
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Assignment 3

The document contains programming assignments for the Department of Information Security at the Islamia University of Bahawalpur, focusing on C++ and C programming fundamentals. It includes various examples of programs using if statements, if-else structures, and switch-case statements to perform calculations and display outputs based on user input. The assignments aim to enhance students' understanding of basic programming concepts and conditional logic.

Uploaded by

lostttbird
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

​ he Islamia University of Bahawalpur,Pakistan​

T
​Department of Information Security​
​`Faculty of Computing​
​Assignment#2​
​Programming Fundamentals​

​ ourse code:CYSE-1301​
C
​Class:BS CySec-Semester 1​
​Course Instructor:Ms. Rabia Kamran​

​1. C++ Program Using simple if statements​


​ include <iostream>​
#
​using namespace std;​

​int main() {​
​float mass, weight;​
​cout << "Enter mass of the object: ";​
​cin >> mass;​
​weight = mass * 9.8;​
​cout << "Weight = " << weight << endl;​
​if (weight >= 1000)​
​cout << "Too heavy object!" << endl;​
​if (weight < 1000)​
​cout << "Too light object!" << endl;​
​return 0;​
​}​
​2. C++ Program Using if-else​
​ include <iostream>​
#
​using namespace std;​
​int main() {​
​float mass, weight;​
​cout << "Enter mass of the object: ";​
​cin >> mass;​
​weight = mass * 9.8;​
​cout << "Weight = " << weight << endl;​
​if (weight >= 1000)​
​cout << "Too heavy object!" << endl;​
​else​
​cout << "Too light object!" << endl;​

​return 0;​
​}​
​ . C++ Program Multiple of 3 and/or 5 using​
3
​if-else-if​
​ include <iostream>​
#
​using namespace std;​
​int main() {​
​int num;​
​cout << "Enter a number: ";​
​cin >> num;​
​if (num % 3 == 0 && num % 5 == 0)​
​cout << "The number is a multiple of both 3 and 5" << endl;​
​else if (num % 3 == 0)​
​cout << "The number is a multiple of 3 only" << endl;​
​else if (num % 5 == 0)​
​cout << "The number is a multiple of 5 only" << endl;​
​else​
​cout << "Neither a multiple of 3 nor 5" << endl;​

​return 0;​
​}​
​4. C Program Temperature Conditions​
​#include <stdio.h>​

​int main() {​
​float temp;​
​printf("Enter temperature in centigrade: ");​
​scanf("%f", &temp);​
​if (temp < 0)​
​ rintf("Freezing weather\n");​
p
​else if (temp >= 0 && temp < 10)​
​printf("Very cold weather\n");​
​else if (temp >= 10 && temp < 20)​
​printf("Cold weather\n");​
​else if (temp >= 20 && temp < 30)​
​printf("Normal weather\n");​
​else if (temp >= 30 && temp < 40)​
​printf("Hot weather\n");​
​else​
​printf("Extremely hot weather\n");​

​return 0;​
​}​
​5. C++ Program Month Name Using switch​
​ include <iostream>​
#
​using namespace std;​

​int main() {​
​int month;​
​cout << "Enter month number (1–12): ";​
​cin >> month;​
​switch (month) {​
​case 1: cout << "January"; break;​
​case 2: cout << "February"; break;​
​case 3: cout << "March"; break;​
​case 4: cout << "April"; break;​
​case 5: cout << "May"; break;​
​case 6: cout << "June"; break;​
​case 7: cout << "July"; break;​
​case 8: cout << "August"; break;​
​case 9: cout << "September"; break;​
​case 10: cout << "October"; break;​
​case 11: cout << "November"; break;​
​case 12: cout << "December"; break;​
​default: cout << "Invalid month number!";​
}​ ​
​return 0;​
​}​

You might also like