.NET Practical Slip 15 Q B

Slip 15 Q.B) Problem Statement

Q. Write a C#.Net program to accept and display ‘n’ customer’s details such as customer_no, Name, address, item_no, quantity, and price. Display the total price of all items. 25 Marks

Answer:

using System;
class Customer
{
    public int CustomerNo;
    public string Name;
    public string Address;
    public int ItemNo;
    public int Quantity;
    public double Price;
}
class Program
{
    static void Main()
    {
        Console.Write("Enter number of customers: ");
        int n = int.Parse(Console.ReadLine());

        Customer[] customers = new Customer[n];
        double totalPrice = 0;

        for (int i = 0; i < n; i++)
        {
            customers[i] = new Customer();
            Console.WriteLine($"\nEnter details for Customer {i + 1}:");

            Console.Write("Customer No: ");
            customers[i].CustomerNo = int.Parse(Console.ReadLine());

            Console.Write("Name: ");
            customers[i].Name = Console.ReadLine();

            Console.Write("Address: ");
            customers[i].Address = Console.ReadLine();

            Console.Write("Item No: ");
            customers[i].ItemNo = int.Parse(Console.ReadLine());

            Console.Write("Quantity: ");
            customers[i].Quantity = int.Parse(Console.ReadLine());

            Console.Write("Price: ");
            customers[i].Price = double.Parse(Console.ReadLine());

            totalPrice += customers[i].Quantity * customers[i].Price;
        }
        Console.WriteLine("\n----- Customer Details -----");
        for (int i = 0; i < n; i++)
        {
            Console.WriteLine($"\nCustomer {i + 1}:");
            Console.WriteLine($"Customer No: {customers[i].CustomerNo}");
            Console.WriteLine($"Name: {customers[i].Name}");
            Console.WriteLine($"Address: {customers[i].Address}");
            Console.WriteLine($"Item No: {customers[i].ItemNo}");
            Console.WriteLine($"Quantity: {customers[i].Quantity}");
            Console.WriteLine($"Price: {customers[i].Price}");
            Console.WriteLine($"Total for this customer: {customers[i].Quantity * customers[i].Price}");
        }
        Console.WriteLine($"\nTotal Price of All Items: {totalPrice}");
    }
}

Helpful Links

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top