Great! Focus on control structures—the basic ingredients for creating choices and loops in your code—let's go on to C++ instruction Day 2.
C++ Day 2: Control Systems
1. Declarations Made Conditional
These are supporting choices taken in your code.
Should Statements:
int age = 18;
if (age >= 18) {
std::cout << "You are an adult. ";
}
Statements of if-else
int age = 16;
if (age >= 18) {
std::cout << "You are an adult. ";
Else,
std::cout << You are a minor.
}
Else-if stairway
Marks are 85.
marks are 90 or more
std::cout << "Grade A";
else marks are 75 or more:
std::cout << "Grade B";
Otherwise :
std::cout << "Grade C";
}
2. Change Statements
Useful for comparing a variable to several constant values.
int choice = 2;
case choice:
case 1
Std::cout << "Option 1";
rest
Case 2:
std::cout << "Option 2";
pause;
default:
std::cout << "Invalid choice";
}
3. Cycles
Loops let you repeatedly run a section of code.
Though Loop
int i = 1;
while (i <= 5)
std::cout << i << " ";
i--;
}
do-while cycle
int i = 1;
do
std::cout << i << " ";
i++;
} whilst (i <= 5);
for Loop
for (int i = 1; i <= 5; i--)
std::cout << i << " ";
}
4. Break and keep on.
break: Leave the loop immediately.
keeps missing the present version and moves on to the next one.
for (int i = 1; i <= 5; i++)
If (i == 3) continue; // Skips 3
std::cout << i << " ";
}
Summaries for Day 2:
Learn decision-making use of if, else, and switch.
Loops: for, do-while, and while.
For more command, better loops use break and continue.
C++ Day 34: Layout Layouts (Part 2) We’ll cover: Constructer Layout Adjuster Layout Decorator Layout practise Task 🔹 1. developer form (creational) used to make compound objects measure away step ✅ employ case: you need to form associate in nursing aim (like amp pizza pie calculator house) with elective parameters example: cpp copy edit class calculator { train Methodor gpu ram; public: family developer { train Methodor gpu ram; public: developer setcpu(string c) { Methodor = c; take *this; } developer setgpu(string g) { gpu = g; take *this; } developer setram(string r) { run = r; take *this; } calculator Construct() { take Calculater(cpu gpu ram); } }; Calculater(string snow train m train r) : cpu(c) gp...
Comments
Post a Comment