ADNANCED STRUCTURE USAGE (DIGGING DEEP IN TO STRUCTTS: CONCEPT BUSTER)

#include <iostream>

using namespace std;

struct nameinfo{//temprlate for struct
string fname;//members of struct
string lname;
int letters;
};
struct nameinfo obj(void);//prototype of function named obj of return type struct nameinfo and //having parameter void

struct nameinfo NOL(struct nameinfo);//prototype of function named NOL of return type struct //nameinfo and parameter of type struct nameinfo

 void showinfo(struct nameinfo);//prototype of function named showinfo of return type void and //parameter struct  nameinfo

 int main(){
struct nameinfo person;//declaration of person varaiable of type struct nameinfo

person=obj();//passing obj() into person

person=NOL(person);//passing NOL() into person variable

showinfo(person);//passing variable of type struct nameinfo named person into showinfo() function

 }

 struct nameinfo obj(void){
     struct nameinfo obj1;
 cout<<"enter your first name "<<endl;
 cin>>obj1.fname;
 cout<<"enter your last name "<<endl;
 cin>>obj1.lname;
 return obj1;
 };

 struct nameinfo NOL(struct nameinfo h ){

h.letters=sizeof(h.fname)+sizeof(h.lname);
 return h;
 };
 void showinfo(struct nameinfo obj){
 cout<<obj.fname<<" "<<obj.lname<<"has "<<obj.letters<<"letters in it "<<endl;
 };







Previous
Next Post »

Comments:

Disqus Shortname