0% found this document useful (0 votes)
29 views15 pages

Demo 3

The document contains C# code for a grocery shop management system using abstract classes and dictionaries. It allows users to add products, sell them, check availability, and remove items from the inventory. The main class provides a user interface for interacting with the system through a console application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views15 pages

Demo 3

The document contains C# code for a grocery shop management system using abstract classes and dictionaries. It allows users to add products, sell them, check availability, and remove items from the inventory. The main class provides a user interface for interacting with the system through a console application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

using System;

using System.Collections.Generic;

using System.Linq;

using System.Security.Cryptography.X509Certificates;

using System.Text;

using System.Threading.Tasks;

namespace DAX_Abstract

public abstract class DAX_Abstract

protected Dictionary<string, int> items_menu = new Dictionary<string,


int>();

public List<int> saleproduct = new List<int>();

protected string product_name, pname;

int pquantity;

public void add_menu()

Console.WriteLine("ENTER THE NUMBER OF ITEMS TO ADD");

int numbercount = Convert.ToInt32(Console.ReadLine());

for (int i = 0; i<numbercount; i++)

Console.WriteLine("ENTER PRODUCT NAME");

pname=Console.ReadLine();
Console.WriteLine("ENTER PRODUCT QUANTITY");

pquantity=Convert.ToInt32(Console.ReadLine());

items_menu.Add(pname, pquantity);

public void display()

foreach (var item in items_menu)

Console.WriteLine(item);

abstract public void sale(string product_name);

public abstract class DAX_Abstract1 : DAX_Abstract

int productvalue;

int product_quantity;

int sales;

override public void sale(string product_name)

if (items_menu.Count!=0)

{
if (items_menu.ContainsKey(product_name))

productvalue=items_menu[product_name];

Console.WriteLine("ENTER THE PRODUCT QUANTITY YOU WISH


TO BUY");

product_quantity=Convert.ToInt32(Console.ReadLine());

if (productvalue>=product_quantity)

sales=productvalue-product_quantity;

saleproduct.Add(sales);

Console.WriteLine("THE PRODUCT BUYED


SUCCESSFULLY"+sales);

else

Console.WriteLine("THE PRODUCT QUANTITY IS OUT OF


STOCK!!!!");

else Console.WriteLine("Invalid");

public void pop(string element)

if (items_menu.Count!=0)
{

if (items_menu.ContainsKey(element))

items_menu.Remove(element);

else

Console.WriteLine("THE ELEMENT NOT FOUND !!!");

else

Console.WriteLine("THERE IS NO ELEMENT !!!");

public void display()

string e = Console.ReadLine();

Console.WriteLine("the value are"); ;

Console.WriteLine(items_menu[e]);

foreach (var s in items_menu)

Console.WriteLine(s);

}
}

}
using System;

using System.Collections.Generic;

using System.ComponentModel.DataAnnotations;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace DAX_Abstract

class Dax_main : DAX_Abstract1

public static void Main(string[] args)

DAX_Abstract1 daxabstract = new Dax_main();

int choice;

while (true)

Console.WriteLine("ENTER USER CHOICE\n 1.Add \n2.Sale\


n3.Availiablity\n4.remove");

choice=Convert.ToInt32(Console.ReadLine());

switch (choice)

case 1:

daxabstract.add_menu();

break;
case 2:

Console.WriteLine("ENTER THE PRODUCT NAME");

string product_name = Console.ReadLine();

daxabstract.sale(product_name);

break;

case 3:

Console.WriteLine("THE PRODUCT AVAILIABILITY");

daxabstract.display();

break;

case 4:

Console.WriteLine("THE ELEEMT SHOULD REMOVE FROM A


LIST");

string element = Console.ReadLine();

daxabstract.pop(element);

break;

case 5:

daxabstract.display();

break;

// abstract public class DAX_Abstract

// {
// protected const int num = 10;

// protected virtual void display()

// {

// Console.WriteLine("hello display on parent class"+num);

// }

// abstract protected void a();

// }

// //interface Ia

// //{

// // public void ia();

// //}

// abstract public class A : DAX_Abstract

// {

// protected const int num = 11;

// public void display()

// {

// Console.WriteLine("hello"+num);

// }

// public void ia()

// {

// Console.Write("hi");

// }

// abstract public void b();

// //override public void a()

// //{

// // Console.WriteLine("This is abstract class call");


// //}

// //override protected void a11()

// //{

// // Console.WriteLine("hello world");

// //}

// //abstract protected void a11();

// }

// //public class B

// //{

// // public void display()

// // {

// // Console.WriteLine("hello"+num);

// // }

// // override public void b()

// // {

// // Console.WriteLine("hello world");

// // }

// // override protected void a11()

// // {

// // Console.WriteLine("hello world");

// // }

// // //abstract protected void cal1();

// //}

// public class c:A

// {
// override protected void a()

// {

// Console.WriteLine("THIS IS DAXA IN PROTECTED METHOD CALLING


A");

// }

// override public void b()

// {

// Console.WriteLine("THIS IS DAXA IN PROTECTED METHOD CALLING


B");

// }

// public static void Main()

// {

// c c1 = new c();

// c1.a();

// c1.b();

// }

// }

//}

DICTIONARY TOPIC BUILT IN FUNCTIONS


using System;

using System.Collections.Generic;

using System.Linq;

using System.Security.Cryptography.X509Certificates;

using System.Text;

using System.Threading.Tasks;

namespace DAX_GroceryShopManagement

//class Class1

//{

// public virtual void display1()

// {

// Console.WriteLine("base class");

// }

//}

//class Class2 :Class1

//{

// public override void display1()

// {

// base.display1();

// Console.WriteLine("derived class");

// }
//}

public class Class2

public static void dictionary()

Dictionary<string, int> dict = new Dictionary<string, int>();

List<int> a = new List<int>();

dict.Add("1", 1);

dict.Add("22", 2);

dict.Add("three", 3);

int c = dict.Count-1;

//to print the keys based on index

Console.WriteLine(dict.Keys.ElementAt(c));

Console.WriteLine(dict.Values.ElementAt(c));

//string findmethod = dict.Find(c => c.StartsWith(1));

//int findindex = dict.IndexOf("three");

if (dict.ContainsKey("1"))

Console.WriteLine("key found and value is "+dict["1"]);

// to get value and print keys


int ele = Convert.ToInt32(Console.ReadLine());

foreach (var item in dict)

if (item.Value==ele)

Console.WriteLine(item.Key);

//from key to print value

string key = Console.ReadLine();

foreach (var item in dict)

if (item.Key==key)

Console.WriteLine(item.Value);

// for print all keys in dict

foreach (var item in dict.Keys)

Console.WriteLine(item);

// **************************** USED TO CLEAR ALL ELEMENT IN


DICT*******************************

//dict.Clear();

Console.WriteLine(dict.Count);

foreach (var item in dict)

Console.WriteLine(dict.Count);
Console.WriteLine(item);

public class List: Class2

public List<int> l1 = new List<int>();

public void list()

l1.Add(1);

l1.Add(2);

l1.Add(3);

l1.Add(4);

l1.AddRange(new int[]{5,6});

l1.Insert(0, 001);

l1.InsertRange(1, new int[] {7,8,93});

foreach (var item in l1)

Console.WriteLine(item);

l1.Remove(111111);

Console.WriteLine("after remove");

foreach (var item in l1)

Console.WriteLine(item);

int findindex = l1.IndexOf(1);


Console.WriteLine("find index="+findindex);

class Class3 : Class2

public static void Main(String[] args)

List lis = new List();

lis.list();

Class2.dictionary();

You might also like