Question

Modern language elements Write a string store class to manage string value in a member variable...

Modern language elements

Write a string store class to manage string value in a member variable named        string. The variable’s value should be setable and retrievable using a property named Data. The string store class must also publish an event which is emitted if the data field’s value is changed to null. The event must provide the number of times the value was changed to null (including the current case) as its parameter. The event should not be emitted if the previous value was also null.

Provide the complete c# code of the String store class as well as a short code snippet that creates an instance of it. Subscribes to the event and prints the number of times the value was changed to null as reported by the event. Don’t use specialized event types define.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C# program to count occurrences of null element
using System;
class LinkedList
{
   Node head; // head of list

   /* Linked list Node*/
   public class Node
   {
       public int data;
       public Node next;
       public Node(int d) {data = d; next = null; }
   }

   /* Inserts a new Node at front of the list. */
   public void push(int new_data)
   {
       /* 1 & 2: Allocate the Node &
               Put in the data*/
       Node new_node = new Node(new_data);

       /* 3. Make next of new Node as head */
       new_node.next = head;

       /* 4. Move the head to point to new Node */
       head = new_node;
   }

   /* Counts the no. of occurrences of a node
   (search_for) in a linked list (head)*/
   int count(int search_for)
   {
       Node current = head;
       int count = 0;
       while (current != null)
       {
           if (current.data == search_for)
               count++;
           current = current.next;
       }
       return count;
   }

   /* Drier function to test the above methods */
   public static void Main(String []args)
   {
       LinkedList llist = new LinkedList();

       /* Use push() to construct below list
        null->2->null->3->null */
       llist.push( );
       llist.push(2);
       llist.push( );
       llist.push(3);
       llist.push( );

       /*Checking count function*/
       Console.WriteLine("Count of 'null' is "+llist.count( ));
   }
}
// This code is contributed by Arnab Kundu

Add a comment
Know the answer?
Add Answer to:
Modern language elements Write a string store class to manage string value in a member variable...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT