please dont rip this site

Language Ccpp Cppref Examples STRUCT1.CC

/ ******************************************************************
 *
 * Purpose: Program to demonstrate struct in C++.
 * Date:    04-Aug-97
 * Author:  M J Leslie.
 * Descrip:
 *
 ******************************************************************/

#include <stdio.h>                          // printf

struct Person
{
    // ... Declare the variables in the 'Person' structure.
    // ... This is normal C syntax.
        
    char Name[35];
    int  Age;

    // ... Declare a function within the structure. This is
    // ... new to C++
    
    int  YearsToRetire(void)         // \
    {                                // ---  Function in a structure.
        return 65-Age;               // ---
    }                                // /
};

// ... Program to test the 'Person' structure.

int main(int argc, char **argc )
{
    // ...  Create a person called Mr Leslie.
        
    Person Mr_Leslie;

    // ...  Put some data into the structure.
        
    strcpy(Mr_Leslie.Name, "Martin");
        
    Mr_Leslie.Age=36;

    // ...  Extract data from the structure.
    // ...  Use the 'YearsToRetire' function to
    // ...  Calculate the number of years this poor
    // ...  soul has to work before retirement.
    
    printf("%s will retire in %d years\n",
           Mr_Leslie.Name,
           Mr_Leslie.YearsToRetire());    // <--  Call the function.

    return (0);
}


file: /Techref/language/ccpp/cppref/EXAMPLES/struct1.cc, 1KB, , updated: 1997/8/3 14:10, local time: 2024/4/27 06:01,
TOP NEW HELP FIND: 
3.142.197.198:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/techref/language/ccpp/cppref/EXAMPLES/struct1.cc"> language ccpp cppref EXAMPLES struct1</A>

Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .