Q:

Write a program in C# Sharp to create a nested structure to store two data for an employee in an array

0

Write a program in C# Sharp to create a nested structure to store two data for an employee in an array.

Test Data:

Create a nested structure and store data in an array :                              
-------------------------------------------------------                          
Name of the employee : H.Rana                                                    
Input day of the birth : 05                                                      
Input month of the birth : 02                                                    
Input year for the birth : 58                                                    
                                                                                 
Name of the employee : S.Mathur                                                  
Input day of the birth : 04                                                      
Input month of the birth : 08                                                    
Input year for the birth : 59 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
    class strucExer3
    {
	//employee is a structure of members eName and dtObirth
        struct employee
        {
            public string eName;
            public dtObirth Date;
        }
	//dtObirth is a nested structure of employee
        struct dtObirth
        {
            public int Day;
            public int Month;
            public int Year;
        }  
        static void Main(string[] args)
        {
            int dd=0, mm=0, yy=0;
            int total = 2;
			Console.Write("\n\nCreate a nested structure and store data in an array :\n");
			Console.Write("-------------------------------------------------------\n"); 	
            employee[] emp = new employee[total];
            for (int i = 0; i < total; i++)
            {
                Console.Write("Name of the employee : ");
                string nm = Console.ReadLine();
                emp[i].eName = nm;
                Console.Write("Input day of the birth : ");
                dd = Convert.ToInt32(Console.ReadLine());
                emp[i].Date.Day = dd;
                Console.Write("Input month of the birth : ");
                mm = Convert.ToInt32(Console.ReadLine());
                emp[i].Date.Month = mm;
                Console.Write("Input year for the birth : ");
                yy = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine();
                emp[i].Date.Year = yy;
            }
        }
    }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now