Ai Notes

Boost Your C++ Skills with Programming Fundamentals Lab Report (4) C++

Hey, Let’s Level Up Your C++ Game!

Hi there, coding newbie! If you’re ready to dig into some core programming concepts, you’re in for a treat. Today, we’re exploring the Programming Fundamentals Lab Report (4) C++, a fun and practical way to sharpen your skills. Whether you’re a student or just curious about C++, this guide breaks it all down with a friendly vibe and easy steps. Let’s jump into the world of operators and problem-solving!


What’s This Lab Report All About?

The Programming Fundamentals Lab Report (4) C++ is designed to give you a solid grasp of basic programming ideas. Here’s what you’ll master:

  • Using arithmetic operators for calculations.
  • Comparing values with relational operators.
  • Working with logical operators for decision-making.
  • Playing with unary operators to tweak values.
  • Simplifying code with the ternary operator.

We’ve got five tasks to tackle, each building your confidence. Ready? Let’s go!


Tools You’ll Need

For this lab, you’ll use:

  • Embarcadero Dev-C++: A beginner-friendly IDE. Grab it here if you don’t have it yet.
  • MS Word: Optional, for documenting your work.

Set up Dev-C++, and you’re all set to code!


Lab Task 1: Basic Arithmetic Operations

What’s the Goal?

Write a program that takes two integers and calculates their sum, difference, product, quotient, and remainder.

The Code

#include <iostream> using namespace std;

int main() { int a, b; cout << “Enter two integers: “; cin >> a >> b; cout << “Sum: ” << a + b << endl; cout << “Difference: ” << a – b << endl; cout << “Product: ” << a * b << endl; cout << “Quotient: ” << a / b << endl; cout << “Remainder: ” << a % b << endl; return 0; }

What You’ll See (Example)

Enter two integers: 10 3 Sum: 13 Difference: 7 Product: 30 Quotient: 3 Remainder: 1

Why It Works

  • Takes two integers (a and b) from the user.
  • Uses +, -, *, /, and % for sum, difference, product, quotient, and remainder.
  • Prints each result with cout—simple and sweet!

Lab Task 2: Comparing Numbers with Relational Operators

What’s the Goal?

Take three floating-point numbers and compare them using relational operators (> , < , ==).

The Code

#include <iostream> using namespace std;

int main() { float a, b, c; cout << “Enter three numbers: “; cin >> a >> b >> c; cout << a << (a > b ? ” > ” : a < b ? ” < ” : ” = “) << b << endl; cout << b << (b > c ? ” > ” : b < c ? ” < ” : ” = “) << c << endl; cout << a << (a > c ? ” > ” : a < c ? ” < ” : ” = “) << c << endl; return 0; }

What You’ll See (Example)

Enter three numbers: 5.5 3.2 7.8 5.5 > 3.2 3.2 < 7.8 5.5 < 7.8

Why It Works

  • Takes three floats (a, b, c).
  • Uses relational operators to compare pairs (a vs. b, b vs. c, a vs. c).
  • Nested ternary operators make it concise and readable.

Lab Task 3: Logical Operators with Boolean Values

What’s the Goal?

Take two boolean values and show the results of logical AND, OR, and NOT.

The Code

#include <iostream> using namespace std;

int main() { bool a, b; cout << “Enter two boolean values (0 or 1): “; cin >> a >> b; cout << “Logical AND: ” << (a && b) << endl; cout << “Logical OR: ” << (a || b) << endl; cout << “Logical NOT of first: ” << (!a) << endl; cout << “Logical NOT of second: ” << (!b) << endl; return 0; }

What You’ll See (Example)

Enter two boolean values (0 or 1): 1 0 Logical AND: 0 Logical OR: 1 Logical NOT of first: 0 Logical NOT of second: 1

Why It Works

  • Takes two bools (0 = false, 1 = true).
  • && (AND) is true if both are true.
  • || (OR) is true if at least one is true.
  • ! (NOT) flips the value.

Lab Task 4: Unary Operator Fun

What’s the Goal?

Show how unary operators (increment, decrement, negation) change an integer.

The Code

#include <iostream> using namespace std;

int main() { int a = 10; cout << “Original value: ” << a << endl; cout << “Pre-Increment: ” << ++a << endl; cout << “Post-Increment: ” << a++ << endl; cout << “After Post-Increment: ” << a << endl; cout << “Pre-Decrement: ” << –a << endl; cout << “Post-Decrement: ” << a– << endl; cout << “After Post-Decrement: ” << a << endl; cout << “Negation: ” << -a << endl; return 0; }

What You’ll See

Original value: 10 Pre-Increment: 11 Post-Increment: 11 After Post-Increment: 12 Pre-Decrement: 11 Post-Decrement: 11 After Post-Decrement: 10 Negation: -10

Why It Works

  • ++a (pre-increment) adds 1 before using the value.
  • a++ (post-increment) uses the value, then adds 1.
  • –a and a– work the same way for decrementing.
  • -a flips the sign.

Lab Task 5: Ternary Operator Check

What’s the Goal?

Use a ternary operator to check if a number is positive or non-positive.

The Code

#include <iostream> using namespace std;

int main() { int a; string ans; cout << “Enter an integer: “; cin >> a; ans = (a >= 0) ? “Positive” : “Negative”; cout << “The number you entered is ” << ans << endl; return 0; }

What You’ll See (Example)

Enter an integer: 7 The number you entered is Positive

Why It Works

  • Takes an integer (a).
  • Ternary operator (condition ? value1 : value2) checks if a >= 0.
  • Assigns “Positive” or “Negative” to ans and prints it.

Why This Lab Is Awesome

The Programming Fundamentals Lab Report (4) C++ builds your foundation with operators—tools you’ll use in every program. From math to logic, you’re getting the hang of problem-solving!


Keep the Coding Vibes Going

Loved this? Dive deeper with C++ operator tutorials on W3Schools or explore more examples on GeeksforGeeks. Practice makes perfect, so keep at it!


Final Thoughts

That’s it for the Programming Fundamentals Lab Report (4) C++! You’ve just tackled arithmetic, relational, logical, unary, and ternary operators—how cool is that? Which task was your favorite? Drop a comment below, or let me know if you want help with your next lab. Happy coding, friends!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top