// File Name: ~ftp/pub/class/cplusplus/Structure/StrucSimple.cpp
// Purpose:   Demonstrates the use of structure in C++.
//            Stores some personal data in a structure, then prints
//            the info out.

#include <iostream>
using namespace std;

int main()
{
        // Defining a structure
        struct PersonalData
        {
                char *FirstName;
                char *LastName;
                char *Birthday;  // in the format of 12/30/1978
                int  PhoneNum;
        }; // don't forget the ending ";"

        // Declaring a variable of type PersonalData
        PersonalData PersonOne;

        // Populate PersonOne with data
        PersonOne.FirstName = "John";
        PersonOne.LastName = "Doe";
        PersonOne.Birthday = "12/30/1978";
        PersonOne.PhoneNum = 5855555;

        // Print the data out
        cout << "PersonOne's First name is: " << PersonOne.FirstName << endl;
        cout << "PersonOne's Last name is: " << PersonOne.LastName<< endl;
        cout << "PersonOne's Birthday is: " << PersonOne.Birthday<< endl;
        cout << "PersonOne's Phone number is: " << PersonOne.PhoneNum<< endl;

        return 0;
}
William Hemsworth commented: Don't waste peoples time. -2
mvmalderen commented: Compile it yourself!! -2

Recommended Answers

All 10 Replies

Member Avatar for iamthwee

Erm do we look like an online compiler service?

commented: Nope, Daniweb isn't :P +11
commented: you are just another Narue fan +4

che_che

Check out the programs comments..

// Stores some personal data in a structure, then prints
// the info out.

I guess that's what the output will be.

commented: Did they write it? hell no, it doesn't look like they even read it! +36

1) put your code in "code" tags
2) compile it yourself and report any errors!

The output would be:

PersonOne's First name is: John
PersonOne's Last name is: Doe
PersonOne's Birthday is: 12/30/1978
PersonOne's Phone number is: 5855555

Then it will exit right away before you actually see your data unless you run it with command prompt.
Plus i think you might receive an error when assigning a pointer like that :/

But I not know why you need it... First- you can just compile it in your compiler. Second- I think it is pretty self-explanatory...
But just for your satisfaction I posted the output.

Ya we are too good for such small programs...Now do it yourself smart fellow...!!!

Here we help people learn and understand programming. We don't answer questions without the questioneer doing work to understand what the problem is and attempting to fix it... Judging from the filename I'd say this is homework and you have no idea what your doing. Unless, of course, your "just testing us";)

If you don't know how to program/ program in c++, and your in a computer science class, use google to lean how to program. "how to program in c++" should do it. Good luck.:)

really i have problems compiling?? on google i dont really understand..

really i have problems compiling?? on google i dont really understand..

You have no idea what you are doing, do you? Let me introduce you to programming. You write code in something called a computer language. A computer language is a mathamatical and logical language to tell the computer what to to. The computer itself can't understand the language, you need a compiler (which is a program) to translate it into machine code (binary instructions). The program in your post is written in a language called C++, so you need a C++ compiler to turn it into a program. This webpage will show you how to install the compiler. Click here to learn C++, the language your program was written in.

Why is someone, who has no idea what programming is, trying to know what the output of a C++ code segment is anyway??

sorry though its my first in c++,,,

they say its more simple than java,,

sorry guys... hiroshe i wont ask for answers but can u help me..

i reli want 2 know c++

they say its more simple than java,,

And who are 'they' ?? My opinion, C++ is way harder than Java, so don't start with wrong notions.

commented: simpler => closer to the machine => have to think more => harder :) +36
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.