0% found this document useful (0 votes)
28 views6 pages

CPP Programming Assignment

The document contains five C++ programs that demonstrate basic input and output operations. The programs include functionalities to compare two integers, determine if a number is even or odd, check divisibility by 3 and 5, and evaluate student grades using both nested if-else and switch statements. Each program prompts the user for input and displays the corresponding results based on the logic implemented.

Uploaded by

moadjini2
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)
28 views6 pages

CPP Programming Assignment

The document contains five C++ programs that demonstrate basic input and output operations. The programs include functionalities to compare two integers, determine if a number is even or odd, check divisibility by 3 and 5, and evaluate student grades using both nested if-else and switch statements. Each program prompts the user for input and displays the corresponding results based on the logic implemented.

Uploaded by

moadjini2
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
You are on page 1/ 6

1) C++ program to get two integers from the keyboard, then compares them and prints the greatest

one:

```cpp

#include <iostream>

using namespace std;

int main() {

int num1, num2;

cout << "Enter two integers: ";

cin >> num1 >> num2;

if (num1 > num2) {

cout << "The greatest number is: " << num1 << endl;

} else if (num2 > num1) {

cout << "The greatest number is: " << num2 << endl;

} else {

cout << "Both numbers are equal." << endl;

return 0;

```

2) C++ program to get an integer from the keyboard and prints whether the number is even or odd:

```cpp

#include <iostream>
using namespace std;

int main() {

int num;

cout << "Enter an integer: ";

cin >> num;

if (num % 2 == 0) {

cout << num << " is even." << endl;

} else {

cout << num << " is odd." << endl;

return 0;

```

3) C++ program to get an integer from the keyboard and prints whether the number is divisible by 3,

5, both, or none:

```cpp

#include <iostream>

using namespace std;

int main() {

int num;

cout << "Enter an integer: ";

cin >> num;


if (num % 3 == 0 && num % 5 == 0) {

cout << num << " is divisible by both 3 and 5." << endl;

} else if (num % 3 == 0) {

cout << num << " is divisible by 3." << endl;

} else if (num % 5 == 0) {

cout << num << " is divisible by 5." << endl;

} else {

cout << num << " is not divisible by 3 or 5." << endl;

return 0;

```

4) C++ program to get student marks and print the grade using nested if...else statement:

```cpp

#include <iostream>

using namespace std;

int main() {

int marks;

cout << "Enter student marks (0-100): ";

cin >> marks;

if (marks < 0 || marks > 100) {

cout << "Invalid marks. Please enter a value between 0 and 100." << endl;
} else {

if (marks >= 90) {

cout << "Excellent" << endl;

} else if (marks >= 80) {

cout << "Very Good" << endl;

} else if (marks >= 70) {

cout << "Good" << endl;

} else if (marks >= 60) {

cout << "Below Average" << endl;

} else if (marks >= 50) {

cout << "Minimal Pass" << endl;

} else {

cout << "Not Passed" << endl;

return 0;

```

5) C++ program to get student marks and print the grade using a switch statement:

```cpp

#include <iostream>

using namespace std;

int main() {

int marks;
cout << "Enter student marks (0-100): ";

cin >> marks;

if (marks < 0 || marks > 100) {

cout << "Invalid marks. Please enter a value between 0 and 100." << endl;

} else {

switch (marks / 10) {

case 10:

case 9:

cout << "Excellent" << endl;

break;

case 8:

cout << "Very Good" << endl;

break;

case 7:

cout << "Good" << endl;

break;

case 6:

cout << "Below Average" << endl;

break;

case 5:

cout << "Minimal Pass" << endl;

break;

default:

cout << "Not Passed" << endl;

break;

}
}

return 0;

```

You might also like