Connecting...

This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Introduction to C++
For more information, please see full course syllabus of Introduction to C++
Introduction to C++ Structures
Lecture Description
In this lesson, our instructor Alvin Sylvain gives an introduction to structures. He starts by discussing keeping data organized, structure declaration and usage, and then accessing members, structure member and initializing member structures. He lastly discusses arrays ofo structures, pointers to structures, structure pointer operator and structure for pointers.
Bookmark & Share
Embed
Share this knowledge with your friends!
Copy & Paste this embed code into your website’s HTML
Please ensure that your website editor is in text mode when you paste the code.(In Wordpress, the mode button is on the top right corner.)
×
Since this lesson is not free, only the preview will appear on your website.
- - Allow users to view the embedded video in full-size.
Next Lecture
Previous Lecture
0 answers
Post by David Amajor on January 6, 2015
this has been soooo helpful, thanks a lot.
3 answers
Tue Nov 4, 2014 10:27 PM
Post by Ram Manohar Oruganti on October 28, 2014
Hi,
So I have three questions on this lecture:
1. You have introduced us to anonymous classes. So, is the user forced to declare any objects of it at the end of the structure declaration?
2. And when we have recursive pointers in function declaration how would the compiler decide as to how much space a struct needs?
3. Why do we need the braces around the structure pointer when dereferencing it during an attempt to access a struct member?
0 answers
Post by Kitt Parker on July 7, 2014
Had another question about structures. Thanks for the assistance with the elusive zero char line.
if I have structure and I try to use this structure with the call
Struct name -> new struct -> string
Test test ("test")
The ("test") would need some kind of constructor, to apply to some variable within the assigned struct? Thanks again. ^^
3 answers
Tue Jun 10, 2014 2:30 PM
Post by Kitt Parker on June 9, 2014
Good Evening Professor,
Perhaps once I have programmed more, it will become more clear. I'm still unsure why you would point to a value instead of just referencing the value directly.
1 answer
Last reply by: Timothy White
Wed Nov 5, 2014 8:03 AM
Post by Nick White on May 26, 2014
i will be very thankful if you could help me with this question.
A high school has 1000 students and 1000 lockers, one locker for each student. On the first day of school, the principal plays the following game: She asks the first student to go and open all the lockers. She then asks the second student to go and close all the even-numbered lockers. The third student is asked to check every third locker. If it is open, the student closes it; if it is closed, the student opens it. The fourth student is asked to check every fourth locker. If it is open, the student closes it; if it is closed, the student opens it. The remaining students continue this game. In general, the nth student checks every nth locker. If the locker is open, the student closes it; if it is closed, the student opens it. After all the students have taken their turn, some of the lockers are open and some are closed. Write a program that prompts the user to enter the number of lockers in a school. After the game is over, the program outputs the number of lockers that are opened. Test run your program for the following inputs: 1000, 5000, 10000. Do you see any pattern developing?
(Hint: Consider locker number 100. This locker is visited by student numbers 1, 2, 4, 5, 10, 20, 25, 50, and 100. These are the positive divisors of 100. Similarly, locker number 30 is visited by student numbers 1, 2, 3, 5, 6, 10, 15, and 30. Notice that if the number of positive divisors of a locker number is odd, then at the end of the game, the locker is opened. If the number of positive divisors of a locker number is even, then at the end of the game, the locker is closed.)
2 answers
Tue Feb 11, 2014 8:02 PM
Post by Ram Manohar Oruganti on February 11, 2014
struct Person{
Person *mom;
Person *dad;
};
How come we have points of data type person within person?
7 answers
Last reply by: John Nielsen
Tue Dec 18, 2012 2:24 PM
Post by John Nielsen on December 13, 2012
Hello Professor I am having an issue with my pointers that I made. First off these are actually classes that I am pointing to. These classes have the methods below. I want my program to be able to enter say five people objects, then list them. Of course the pointers are giving me trouble. Is this the proper way to implement this type of functionality?
void CreatePerson()
{
Person * people = new Person[ArraySize];
for(int i = 0; i < ArraySize; i++)
{
people[i].setFirstName();
people[i].setLastName();
people[i].setAge();
people[i].setHomePhone();
people[i].setCellPhone();
people[i].setWorkPhone();
people[i].setAddress();
}
delete people;
}
//Here I am trying to pass in the existing people object and display its values
void print(Person * people) //This method displays entered values to the screen
{
for(int i = 0; i < ArraySize; i++)
{
cout << people[i].firstName << endl;
cout << people[i].lastName << endl;
cout << people[i].age << endl;
cout << people[i].homePhone << endl;
cout << people[i].cellPhone << endl;
cout << people[i].workPhone << endl;
cout << people[i].address << endl;
cout << people[i].city << endl;
cout << people[i].state << endl;
cout << people[i].zip << endl;
}
//TODO: Display Entered values to the Screen
}
};
//Here is the case statement in my main function that uses the above functions. This is were I run into problems.
case 1 :
*people.print(people);
break;
case 2 :
*people.CreatePerson();
break;
case 3 :
cout << "Goodbye
";
break;