Monday, October 12, 2015

c++ create a user defined variable

#include <iostream>
#include <string>
using namespace std;

void inputdata(); //function
void displaydata(); //function

struct emprec //user define data type
{
string firstname;
string lastname;
int age;
};

emprec emparray[3]; //create a new array with the created data type

void main() //main function
{
inputdata(); //function calling
system("cls");
displaydata();//function calling

system("pause");
}

void inputdata() //using array with the created data type
{
for (int i=0;i<3;i++)
{
cout<<"Enter first name; ";
cin>>emparray[i].firstname//Enter data into the array
cout<<"enter last name: ";
cin>>emparray[i].lastname//Enter data into the array
cout<<"Enter age: ";
cin>>emparray[i].age; //Enter data into the array
cout<<"\n";
cout<<"\n";
}
}

void displaydata() //display entered data
{
for (int i=0;i<3;i++)
{
cout<<"Display first name; ";
cout<<emparray[i].firstname;
cout<<endl;
cout<<"Display last name: ";
cout<<emparray[i].lastname;
cout<<endl;
cout<<"Display age: ";
cout<<emparray[i].age;
cout<<"\n";
cout<<"\n";
}
}

No comments:

Post a Comment

lakshanenosh@gmail.com