Respuesta :
Answer:
C# code for the problem is given below
Explanation:
Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PartsDemo
{
class Parts
{
int partNum;
string partName, partDescription;
double cost;
public Parts(int no,string name,string desc,double cst)
{
partNum = no;
partName = name;
partDescription = desc;
cost = cst;
}
public void print()
{
Console.WriteLine("Part Number: "+partNum );
Console.WriteLine("Part Name: "+partName );
Console.WriteLine("Part Description: "+partDescription );
Console.WriteLine("Cost: "+cost);
}
}
class Program
{
static void Main(string[] args)
{
int numObjects;
Console.Write("How many objects you wish to enter: ");
numObjects = Convert.ToInt32(Console.ReadLine());
//array of objects
Parts[] parts = new Parts[numObjects];
int no;
string name, desc;
double cst;
//entering details of parts from user
for (int i = 0; i < numObjects; i++)
{
Console.Write("Enter part no: ");
no = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter part name: ");
name = Console.ReadLine();
Console.Write("Enter description: ");
desc = Console.ReadLine();
Console.Write("Enter cost: ");
cst = Convert.ToDouble(Console.ReadLine());
parts[i] = new Parts(no,name,desc,cst);
}
Console.WriteLine("\nMenu options: ");
Console.WriteLine("------------------");
for (int i = 0; i < numObjects; i++)
{
Console.WriteLine(i+". Part"+(i+1));
}
//view the selected part by entering its index number
int index;
Console.Write("\nPlease enter the index of a part to view data: ");
index = Convert.ToInt32(Console.ReadLine());
parts[index].print();
Console.ReadKey();
}
}
}