can anyone 't me example of struck

Apr 16, 2013 at 2:42am
because i don't understand
Apr 16, 2013 at 2:50am
Example wrote:
The storm was so terrible that anyone to be struck by lightning was instantly vaporized.
Apr 16, 2013 at 3:11am
sorry i mean struct
Apr 16, 2013 at 3:16am
closed account (3qX21hU5)
struct is the exact same as class except it is public by default instead of private. They are mainly used to combine multiple variables into one object. For example

1
2
3
4
5
6
struct Person
{
    int age;
    string name;
    string favoriteColor;
}


is the same as

1
2
3
4
5
6
7
class Person
{
public:
    int age;
    string name;
    string favoriteColor;
}


and it can be used like

1
2
3
4
5
6
7
int main()
{
    Person me;
    me.age = 23;
    me.name = "Brandon";
    //ect...
}


You can also check out our great tutorial here http://www.cplusplus.com/doc/tutorial/classes/
Apr 16, 2013 at 3:25am
i'm so confuse why the output so fast
i just can see the beginning the out put nor the last

// array of structures
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

#define N_MOVIES 3

struct movies_t {
string title;
int year;
} films [N_MOVIES];

void printmovie (movies_t movie);

int main ()
{
string mystr;
int n;

for (n=0; n<N_MOVIES; n++)
{
cout << "Enter title: ";
getline (cin,films[n].title);
cout << "Enter year: ";
getline (cin,mystr);
stringstream(mystr) >> films[n].year;
}

cout << "\nYou have entered these movies:\n";
for (n=0; n<N_MOVIES; n++)
printmovie (films[n]);
return 0;
}

void printmovie (movies_t movie)
{
cout << movie.title;
cout << " (" << movie.year << ")\n";
system("PAUSE");
}
Apr 16, 2013 at 9:14am
i just can see the beginning the out put nor the last

The code as written seems to work.
It pauses after every line of output. You could change that by putting the pause at the end of main() (just before the return 0;) instead of at the end of printmovie().
Topic archived. No new replies allowed.