431 subscribers
154 photos
10 videos
25 files
66 links
For Any Information @TechnerdGuy
πŸ†˜ Pre-Engineering Students Struggling with C++? πŸ˜₯ Fear not! πŸ’ͺ This channel is your coding lifesaver! πŸš‘ Learn the basics, ace your course! πŸ’―
Download Telegram
C++ Basics
Photo
#2

#include <iostream>
#include <cmath>
using namespace std;
const double PI = 3.141592653589793;

int main() {
    double radius;
    double volume;

    cout << "Volume Sphere Calculator" << endl;
    cout << "Enter radius: ";
    cin >> radius;

    if (radius < 0) {
        cout << "Error: Radius cannot be negative." << endl;
        return 1;
    }

    volume = (4 * PI * pow(radius, 3)) / 3;
    cout << "The Volume Sphere is: " << volume << endl;
    return 0;
}
πŸ‘8πŸ₯°3
C++ Basics
Quiz Scenario: Create two variables that accept name and age, then display them to the user. you should use appropriate data types
#include <iostream>

using namespace std;

int main() {
    string name;
    int age;

    cout << "Please enter your name: " << endl;
    cin>>name;

    cout << "Please enter your age: " << endl;
    cin >> age;


    cout << "Name: " << name << endl;
    cout << "Age: " << age << endl;

    return 0;
}
πŸ‘9
Quiz
What's the output of this code and if you got error fix it and explain why it occur?

#include <iostream>
using namespace std;


void add();

int main() {
    int age = 21;
    add();
    return 0;
}

void add() {
    cout << "Age: " << age << endl;
}
Forwarded from Dagi
#include <iostream>
using namespace std;

int age = 21;

void add() {
cout << "Age: " << age << endl;
}

int main() {
add();
return 0;
}
Like this
πŸ‘4πŸ€”2πŸ‘1
This one also possible



#include <iostream>
using namespace std;
int age = 21;

void add();

int main() {
     add();
    return 0;
}

void add() {
    cout << "Age: " << age << endl;
}

Output :21
Ehen ensera ena lezare yebekanal
Write the output of thisπŸ‘‡ code?

#include <iostream>
using namespace std;

int main( ) {
int n = 4, k = 2;
cout<< ++n << endl;

cout<< n++ << endl;
cout<< n << endl;
cout<< --n << endl;
cout<< n << endl;
cout<< n--<< endl;

cout<< n + k << endl;
cout<< k << endl;
cout<< " n" << endl;
cout<< "\n" << endl;
cout<< " n * n = ";
cout<< n * n << endl;
cout<< 'n' << endl;
return 0;
}
πŸ‘8πŸ‘1
1.
#include <iostream>
using namespace std;

int main() {
    int numb1, numb2;

    cout << "Please Enter Number 1:" << endl;
    cin >> numb1;
    cout << "Please Enter Number 2:" << endl;
    cin >> numb2;
    cout << "X + Y :" << numb1 + numb2 << endl;

    if (numb2 != 0) {
        cout << "X / Y :" << numb1 / numb2 << endl;
    }
    cout << "X * Y :" << numb1 * numb2 << endl;
    cout << "X - Y :" << numb1 - numb2 << endl;

    if (numb1 > numb2) {
        cout << "Number " << numb1 << " is Greater than Number " << numb2 << endl;
    } else if (numb1 < numb2) {
        cout << "Number " << numb1 << " is Greater than Number " << numb2 << endl;
    } else {
        cout << "They are equal" << endl;
    }
    return 0;
}
πŸ₯°5πŸ‘4
C++ Basics
Photo
2.
#include <iostream>

using namespace std;

const double PI = 3.14159265358979323846; 

int main() {
    double radius;
    double circumference;

    cout << "Please enter the radius: " << endl;
    cin >> radius;

    if (radius <= 0) {
        cout << "Radius must be a positive number." << endl;
        return 1;
    }

    circumference = 2 * PI * radius;

    cout << "The circumference of the circle is: " << circumference << endl;
    return 0;
}
πŸ‘2πŸ”₯2
3..
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    double root1, root2;
    int a, b, c;
    double discriminant, square;

    cout << "Please Enter coefficient A:" << endl;
    cin >> a;
    cout << "Please Enter coefficient B:" << endl;
    cin >> b;
    cout << "Please Enter coefficient C:" << endl;
    cin >> c;

    cout << a << "x^2+" << b << "x+" << c << endl;

    if (a == 0) {
        cout << "Division by zero isn't possible" << endl;
        return 1;
    }

    discriminant= pow(b, 2) - (4 * a * c);
   
     if(discriminant>0){
     square =sqrt(discriminant);
    root1 = (-b + square) / (2 * a);
    root2 = (-b - square) / (2 * a);
    cout << "Root1 :"<<root1 << endl;
    cout << "Root2 :"<<root2<< endl;
    }else if(discriminant==0){
    square =sqrt(discriminant);
    root1=(-b)/(2*a);
    cout << "Root: " << root1<< endl;
    }else{
    cout << "The equation is complex number"<< endl;
    }

   
    return 0;
}
πŸ‘3πŸ”₯2
.
Input a string and count the vowels(a,e,I,o,u) . Algorithm,pseudocode and flowchart.please do me this .
#include<iostream>
#include<string>
using namespace std;

int main()
{
    string name;
    cout << "Enter A text " << endl;
    getline(cin,name);
    int count=0;
    for(int i=0; i<name.length(); i++) {
        switch(name[i])
        {
        case 97:
        case 65:
            count++;
            break;

        case 101:
        case 69:
            count++;
            break;
        case 105:
        case 73:
            count++;
            break;
        case 111:
        case  79:
            count++;
            break;
        case 117:
        case 85:
            count++;
            break;
        }
    }
    if(count==0) {
        cout << "There is no vowels" << endl;
    }
    else {
        cout << "There are "<<count<<" vowels" << endl;
    }
    return 0;
}
πŸ‘5
Function


βœ…What is a Function?
A function is a reusable block of code that performs a specific task.


Think of a vending machine:
- Input (Parameters): You select a snack (e.g., B3 for chips).
- Process (Function Body): The machine processes your request.
- Output (Return Value): It delivers the chips.



βœ…Function Components
a) Declaration (Menu)
// Like the vending machine's menu  
int getDrink(int selection);


- Tells the compiler a function exists.

b) Definition (Machine Internals)
// Like the machine's internal mechanism  
int getDrink(int selection) {
if (selection == 1) return COKE;
else return WATER;
}



c) Call (Pressing the Button)**
int myDrink = getDrink(1);  // Output: COKE  





βœ…Types of Functions
-Library Function
sqrt(25) (from <cmath>)

-User-Defined
calculateTax(income)

βœ…Parameter Passing
a) Call by Value (Photocopy)
void printReceipt(int amount) {  
// Works with a COPY of the original
cout << "Amount: " << amount;
}


- Like giving a photocopy of your ID – changes don’t affect the original.

b) Call by Reference (Original Document)
void updateBalance(int &account) {  
account -= 100; // Modifies the ORIGINAL
}


- Like signing the original contract – changes are permanent.

Example:
int wallet = 500;  
updateBalance(wallet); // wallet becomes 400




βœ…Why Use Functions?
Reusability: Like a recipe you reuse (e.g., calculateInterest()).

Modularity: Break problems into smaller parts (e.g., login(), checkout()).

Debugging: Fix one function without breaking others.

βœ…Exam-Style Example :
// Function to check even numbers  
bool isEven(int num) {
return (num % 2 == 0);
}





βœ…Common Mistakes
1.Missing Return Statement:

   int sum(int a, int b) {  
a + b; // Error! No return.
}



2.Incorrect Parameters:

   void greet(string name) { ... }  
greet(); // Error! Missing argument.





βœ… Real-World Coding Example
Scenario: A coffee shop calculator.

#include <iostream>  
using namespace std;

// Function to calculate total cost
float calculateTotal(int coffees, float price) {
return coffees * price;
}

int main() {
int cups = 3;
float cost = calculateTotal(cups, 2.5);
cout << "Total: $" << cost; // Output: $7.5
return 0;
}



Key Insight:
- calculateTotal is like a cashier – you give inputs (cups, price), it returns the result.
❀3πŸ”₯3😁1