Write a program to define a two dimensional array of numbers to store 5 rows and 6 columns. Write a code to accept the data, assign it in array, and print the data entered by the user.
Define a single dimension array of strings to hold the name of City. Accept some values from the user and store them in the array. Use foreach loop to print all the data of the array.
Create a class named ProductDemo which accepts the details of the product, converts the details into reference types using boxing and displays them by converting them into their relevant types using unboxing and calculate the amountPayable. Refer the class diagram given below.
Input:-
Enter the id of product : 101
Enter the name of the product : Segate HDD
Enter Price : 9000
Enter quantity : 2
Output:-
Product Details :
Product id : 101
Product name : Segate HDD
Price : 9000
Quantity : 2
Amt Payable : 18000.00
using System;
namespace Questions
{
class Program
{
class Product
{
public int ID { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
}
class ProductDemo
{
public static void Demo()
{
Console.Write("Enter the id of product : ");
int ID = int.Parse(Console.ReadLine());
Console.Write("Enter the name of the product : ");
string name = Console.ReadLine();
Console.Write("Enter Price : ");
decimal price = decimal.Parse(Console.ReadLine());
Console.Write("Enter quantity :");
int quantity = int.Parse(Console.ReadLine());
Product product = new Product() { ID = ID, Name = name, Price = price, Quantity = quantity };
Console.WriteLine("\n");
Console.WriteLine("Produce Details: ");
Console.WriteLine("Product id : " + product.ID);
Console.WriteLine("Product name : " + product.Name);
Console.WriteLine("Price: " + product.Price);
Console.WriteLine("Quantity: " + product.Quantity);
decimal amountPayable = product.Price * product.Quantity;
Console.WriteLine("Amt Payable : " + amountPayable.ToString("0.00"));
}
}
static void Main()
{
double[,] numbers = new double[5, 6];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 6; j++)
{
Console.Write("Enter number: ");
numbers[i, j] = double.Parse(Console.ReadLine());
}
}
Console.Write("\nnumbers: ");
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 6; j++)
Console.Write(numbers[i, j] + " ");
}
Console.WriteLine("\n");
string[] cities;
Console.Write("Enter cities(split by space): ");
cities = Console.ReadLine().Split();
foreach (string city in cities)
Console.Write(city + " ");
Console.WriteLine("\n");
ProductDemo.Demo();
Console.ReadKey();
}
}
}
Comments
Leave a comment