C++ Structures for beginners (explained in 30 minutes) + Test your programming knowledge!

preview_player
Показать описание
📚 Learn how to solve problems and build projects with these Free E-Books ⬇️

Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.

I use it to enhance the performance, features, and support for C, C#, and C++ development in Visual Studio.
It is a powerful, secure text editor designed specifically for programmers.

In this video, I'm explaining C++ structures for beginners. Structures are user-defined data types. They are used to represent information about something more complicated than a single number, character, array of numbers, characters, etc. So, you can use a structure to represent information about a Person, an Animal, a Sport, a Game, a Car...

In this 30-minute programming tutorial, you will learn what are structures in programming, how to create structures, why to use them, how to create variables of the struct type.
All of these topics are covered in the "Introduction to structures" part of this video.
You'll also learn how to use structures and functions and how to pass a structure as a parameter to a function.
In the final part of the video, I'll show you what are nested structures and how to use structure inside another structure

In the end, you can find a task that you can use to test your programming knowledge, together with some useful tips.
In the description, you can also find videos that can help you to solve the programming test.

However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ❤️😇

Contents:
00:00 - Intro
01:08 - Introduction to C++ structures for beginners
15:28 - C++ structures and functions
20:38 - Nested structures, How to use struct inside another struct
27:05 - Test your programming knowledge!
29:29 - Review of the program that you should build
31:42 - Tips to solve the programming test
34:04 - Suggestions to upgrade the program

Videos that can help you to solve the programming test:

Related videos:

Add me on:
Рекомендации по теме
Комментарии
Автор

📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.

CodeBeauty
Автор

#include <iostream>
using std::cout;
using std::cin;
using std::string;
using std::endl;



struct ** Struct with question + 3 answer and a int for the correct choice **
string questionText;
string answer[3];
int correctAnswer= NULL;
};



bool correctAnswer(int correct) ** ask and check if the answer is correct or not with a bool **
int answer;

cout << "Choose 1-3 : ";
cin >> answer;

while (answer > 3 || answer < 1) { // Check if the user enter a not valid number
cout << "Invalid, Choose 1-3 : ";
cin >> answer;
}

if (answer == correct) check if the answer is correct
cout << "Correct !" << endl << endl;
return return 1 if valid, 0 if not
}
else{
cout << "Not correct :(" << endl << endl;
return false;
}
}



bool question(Question questionNumber) { // ** List all option
cout << questionNumber.questionText << endl;
for (int j = 0; j < 3; j++) {
cout << questionNumber.answer[j] << endl;
}
return Use the function correctAnswer for asking and checking the answer and return 1 if correct, 0 if not.
}



int main(){
int score = Just for counting the score.

Question create all question with structure here, i don't think we can use a loop for that, cause of all differentes text
question1.questionText = "What is the smallest country ?";
question1.answer[0] = "1. USA";
question1.answer[1] = "2. India";
question1.answer[2] = "3. Vatican City";
question1.correctAnswer = send the correct option to my function



Question question2;
question2.questionText = "What is the biggest animal in the world ?";
question2.answer[0] = "1. Elephant";
question2.answer[1] = "2. Blue whale";
question2.answer[2] = "3. Great white shark";
question2.correctAnswer = 2;



Question question3;
question3.questionText = "How many elements are there in the periodic table of element ?";
question3.answer[0] = "1. 118 elements";
question3.answer[1] = "2. 119 elements";
question3.answer[2] = "3. 120 elements";
question3.correctAnswer = 1;



Question question4;
question4.questionText = "155 % 10 ?";
question4.answer[0] = "1. 15";
question4.answer[1] = "2. 5";
question4.answer[2] = "3. 15, 5";
question4.correctAnswer = 2;



Question question5;
question5.questionText = "Where is Bali";
question5.answer[0] = "1. Malaysia";
question5.answer[1] = "2. Venezuela";
question5.answer[2] = "3. Indonesia";
question5.correctAnswer = 3;



score += if the player choose the correct option the bool function return 1 and add this to my score
score += else, if the player fail, we get 0 and the score don't change
score += question(question3);
score += question(question4);
score += question(question5);



cout << "Your score is : " << score << " /5." << endl;
cin.get();
}

SpoonerBlackWolf
Автор

please post c++ algorithms and data structures full course. thanks

Eliel
Автор

You are amazing, but you forgot to answer the most important question of all - what is the difference between a struct and a class... the answer is:

The only difference between a struct and class in C++ is the default accessibility of member variables and methods. In a struct they are public; in a class they are private (at least per my understanding).

peter
Автор

//Task Completed👍
#include<iostream>
using namespace std;

struct quiz{
string question;
string option1;
string option2;
string option3;
int answer;
};

void display(quiz q){
cout<<q.question<<endl;
cout<<q.option1<<endl;
cout<<q.option2<<endl;
cout<<q.option3<<endl;
cout<<"Choose 1-3"<<endl;
}

void check(quiz q, int x){
if(q.answer==x){
cout<<"Correct!"<<endl;
}else{
cout<<"Wrong!"<<endl;
}
cout<<endl;
}



int main(){

quiz q1;
q1.question="Who is founder of c++ language?";
q1.option1="1.James Gosling";
q1.option2="2.Bjarne Stroustrup";
q1.option3="3.Dennis Ritchie";

quiz q2;
q2.question="Which is the largest country in the world?";
q2.option1="1.Russia";
q2.option2="2.Canada";
q2.option3="3.India";

quiz q3;
q3.question="Which is the closest planet to earth?";
q3.option1="1.Mars";
q3.option2="2.Jupiter";
q3.option3="3.Mercury";

quiz q4;
q4.question="What is the capital of India?";
q4.option1="1.Mumbai";
q4.option2="2.New Delhi";
q4.option3="Kolkata";

quiz q5;
q5.question="Orkut.com is now owned by
q5.option1="Facebook";
q5.option2="Samsung";
q5.option3="Google";

display(q1);
cin>>q1.answer;
check(q1, 2);


display(q2);
cin>>q2.answer;
check(q2, 1);

display(q3);
cin>>q3.answer;
check(q3, 3);

display(q4);
cin>>q4.answer;
check(q4, 2);

display(q5);
cin>>q5.answer;
check(q5, 3);



return 0;
}

nikhiljha
Автор

My God, you´re like an angel that came to teach us C++! Thank you so much!

manuelalejandrohernandezma
Автор

I am actually writing an ORM to abstract my SQL statements. One of the thing I did was create a way to map my C structures into the ORM like a virtual structure. Heavy use of pointers to the structure elements was used and became very helpful in the abstraction.

colinmaharaj
Автор

This teacher really wants a lot of comments and likes and shares.
Lets give her it.
Thank you for the free tutorial.

patrpatl
Автор

Youre teaching method is excellent, you deserve more views. Dont stop, youll go wayy big some day!

zaeshanvlogs
Автор

I was wondering when to use a struct and when to use classes + objects. 2) I think it is always good to show the teacher's solution so we can compare it with ours! Thx for nice tutorials..

SA-ojbo
Автор

Great explanation! My interest in coding is being developed by watching your videos and by practicing them. Thanks a lot

prasannakayitha
Автор

I didn't understand that part where you said create a structure for answers as well but this is how I did it. I hope it's fine this way as well. It's working completely fine. Please check it out. #include <iostream>
#include <string>

struct Question
{
std::string Questiontext;
std::string options[3];
int Correctanswer;
};

int main()
{
Question question[3];

question[0] = {
"What's your favorite animal?",
{"Dog", "Cat", "Rabbit"},
2};

question[1] = {
"What is your favorite show?",
{"Drake & Josh", "BTR", "iCarly"},
1};

question[2] = {
"What is your favorite color?",
{"blue", "green", "red"},
1};

for (int i = 0; i <= 2; i++)
{
int userInput;
std::cout << question[i].Questiontext << std::endl;
std::cout << "1. " << question[i].options[0] << std::endl;
std::cout << "2. " << question[i].options[1] << std::endl;
std::cout << "3. " << question[i].options[2] << std::endl;
std::cout << std::endl;
std::cout << "Choose 1-3 : ";
std::cin >> userInput;

if (userInput == question[i].Correctanswer)

std::cout << "Correct" << std::endl;
else
{
std::cout << "Incorrect" << std::endl;
}
}
}

sinno
Автор

Mam I have a request .Can You Please make a tutorial on "File and Exception handling " in c++

tushargoutam
Автор

#include <iostream>
using namespace std;

int main()
{
const int ANSWER_COL = 4;
const int ARRAY_ROW_SIZE = 5;
const int ARRAY_COL_SIZE = 5;
const int BASE_INDEX = 0;

short int iCorrectCount = 0;

string strAnswer = "";

printf("\n Choose the correct answer from the given options.\n");
printf(" There are five questions to answer and for each question, you must choose\n");
printf(" from the three options provided, which is the correct answer... \n\n");
printf(" ... Good Luck!/Bahati njema!\n");

string = {
{"a) Who was SA's first democratic president?", "1. T.M. Mbeki", "2. H.W. de Klerk", "3. N. Mandela", "3"},
{"b) Which is the biggest soccer team in South Africa?", "1. Kaizer Chiefs", "2. Orlando Pirates", "3. Mamelodi Sundowns", "1"},
{"c) Which of these planet is the closest to the Sun?", "1. Mars", "2. Jupiter", "3. Mercury", "3"},
{"d) Which mammal has 98% of genealogy similar to homo sapiens'?", "1. Monkey", "2. Chimpanzee", "3. Orangutan", "2"},
{"e) Which member of the pop group New Edition was ejected from the group?", "1. M. Bivin", "2. B. Brown", "3. R. Bell", "2"} };

for (int i=0;i<ARRAY_ROW_SIZE;i++) {
// print the question ...
cout << queArray[i][BASE_INDEX] << endl;

// print the three possible answers ...
cout << endl;
for(int j=1; j<ARRAY_COL_SIZE-1; j++) {
cout << queArray[i][j] << endl;
}
cout << endl;
// Enter the answer choice ...
cout << "Choose one of 1 - 3: ";
cin >> strAnswer;

if (strAnswer == queArray[i][ANSWER_COL]) {
printf("\n Congratulations! Correct!\n\n");
iCorrectCount++;
} else {
printf("\n Ooop! Incorrect!\n\n");
}
}

switch (iCorrectCount) {
case 0: {
printf(" You got NOT even a single answer correct. This is a crisis!\n");
break;
}
case 1 : {
printf(" You got only a single answer correct. YOU ARE NOT ALLOWED TO BREED!!!\n");
break;
}
case 2: {
printf(" You got 2 out of [%d]. There is hope for you!\n", &ARRAY_ROW_SIZE);
break;
}
case 3: {
printf(" You got 3 out of [%d]. You need to read a bit more, friend!\n", &ARRAY_ROW_SIZE);
break;
}

case 4: {
printf(" You got 4 out of [%d]. Not bad at all!\n", &ARRAY_ROW_SIZE);
break;
}
case 5: {
printf(" Excellent! You are allowed to breed!!! \n");
break;
}
default:
printf("\n THIS SHOULD NEVER BE DISPLAYED!!!\n");
exit (999);
}
cout << endl; system("pause"); return 0;
}

chippandenga
Автор

I love C++! I'll give it a try to the quiz app this weekend on my free time. Thanks Saldina, you have helped me a lot!

sprintwithcarlos
Автор

For last 5 day I am just searching out your channel and you even write a comment to me this morning. It is finally feeling me like "I CAN UNDERSTAND!" thanks for everything, you are the best teacher ever!

salihbarknakkaya
Автор

Hello Saldina, I am learning to code in order to create a trading robot in Metatrader 5. I find your teaching moves along nicely. Thank you for doing these C++ lessons.

steveperrott
Автор

Programming is fascinating it can make our life more easier I'm lazy and hate doing things on repeat

m_here
Автор

Thank you, I think nobody explains anything better than you do. You are great!!!

chippandenga
Автор

Namaste Saldina! Your teaching approach is so cool.
Gotta tell you, this is the best c++ channel.
keep up the good work.

grasshopper