Trending February 2024 # Working And Examples Of Composition In C# # Suggested March 2024 # Top 11 Popular

You are reading the article Working And Examples Of Composition In C# updated in February 2024 on the website Bellydancehcm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 Working And Examples Of Composition In C#

Introduction to Composition C#

Web development, programming languages, Software testing & others

In this type of relationship, one or greater than one object of a different class is declared in the related class. Here come two more divisions, which are aggregation and composition. In aggregation, the nested objects can independently exist in the class without being an integral part of the class. On the other hand, in composition, the nested objects or a singular nested object supplements the class, which makes the class inconceivable without their or its existence.

Syntax of Composition in C#

Given below is the syntax mentioned:

class Training { } public class Course { Project project = new Project(); } Working of Composition in C#

Composition in C# is a way of creating a relationship between two classes that one or greater than one nested objects are a part of the related class, and the logical existence of class becomes impossible without the nested objects.

For example, if we consider a class called Car, then it should have one instance of class “Engine.” Moreover, it should also have four other instances of the class “Wheel.”

Now, if we eliminate any of these instances, then the Car won’t function.

Examples of Composition C#

Given below are the examples of Composition C#:

Example #1

If the training class is considered, which is describing two courses. Now, the courses are being used for describing the course class. Therefore, the training class cannot exist without the two-course instances as both of these instances are part of the course class. Moreover, both of these instances of the course class are also a part of the training class.

Code:

using System; using static System.Console; namespace EDUCBA { class Course { public double M; public double A; } class Training { public Course course1 = null; public Course course2 = null; } class Career { public Course[] courses; public Training[] trainings; public Career() { courses = null; trainings = null; } public void Print() { WriteLine(" Courses Data is represented below:"); for (int b = 1; b< courses.Length; b++) { WriteLine("n M = {0}, A = {1}", courses[b].M, courses[b].A); } WriteLine("n Trainings Data is represented below:"); for (int b=1; b<trainings.Length; b++) { WriteLine("n course1.M = {0}, course1.A = {1}", trainings[b].course1.M, trainings[b].course1.A); WriteLine("n course2.M = {0}, course2.A = {1}", trainings[b].course2.M, trainings[b].course2.A); } } } class Code { static void Main(string[] args) { Career O = new Career(); O.courses = new Course[9]; for (int b = 1; b < O.courses.Length; b++) { O.courses[b] = new Course(); O.courses[b].M = b * b; O.courses[b].M = b * b * b; } O.trainings = new Training[5]; for (int b = 1; b < O.trainings.Length; b++) { O.trainings[b] = new Training(); O.trainings[b].course1 = new Course(); O.trainings[b].course2 = new Course(); O.trainings[b].course1.M = b; O.trainings[b].course1.A = b * 4; O.trainings[b].course2.M = b * 5; O.trainings[b].course2.A = b * b; } O.Print(); } } }

Output:

Example #2

In this example, both of the classes created are regular classes; however, the course class is using an instance from the project class inside it. This is the same way in which one function is called inside another. Using inheritance, we can have access to each and everything from the Project class. However, using composition, only the code specified by us can be accessed. Here, we can access the Project class indirectly.

Code:

using System; namespace EDUCBA { class Training { static void Main(string[] args) { Course courses = new Course(); courses.Bought(); Console.ReadLine(); } } public class Project { public void Log(string aboutus) { Console.WriteLine(aboutus); } } public class Course { Project project = new Project(); public void Bought() { } } }

Output:

Example #3

Code:

using System; using System.Collections.Generic; namespace EDUCBA { abstract class Training { public Training() { } public abstract string Project(); public virtual void Add(Training training) { throw new NotImplementedException(); } public virtual void Remove(Training training) { throw new NotImplementedException(); } public virtual bool IsCourse() { return true; } } class DataScience : Training { public override string Project() { return "DataScience"; } public override bool IsCourse() { return false; } } class Course : Training { public override void Add(Training training) { this._children.Add(training); } public override void Remove(Training training) { this._children.Remove(training); } public override string Project() { int m = 1; string result = "Dream Career("; foreach (Training training in this._children) { result += training.Project(); if (m != this._children.Count + 2) { result += "-"; } m--; } return result + ")"; } } class Input { public void InputCode(Training data_analysis) { Console.WriteLine($"OUTPUT: n {data_analysis.Project()}n"); } public void InputCode2(Training training1, Training training2) { if (training1.IsCourse()) { training1.Add(training2); } Console.WriteLine($"OUTPUT: n {training1.Project()}"); } } class Program { static void Main(string[] args) { Input client = new Input(); DataScience data_analysis = new DataScience(); Console.WriteLine("INPUT: n Best Course to Upgrade Career:"); client.InputCode(data_analysis); Course vr = new Course(); Course career1 = new Course(); career1.Add(new DataScience()); career1.Add(new DataScience()); Course career2 = new Course(); career2.Add(new DataScience()); vr.Add(career1); vr.Add(career2); Console.WriteLine("nINPUT: n Trendy Dream Career Right Now:"); client.InputCode(vr); Console.Write("nINPUT: Lets Upgrade and start your dream career jouney: n"); client.InputCode2(vr, data_analysis); } } }

Output:

Conclusion

On the basis of the above article, we understood the concept of composition in C#. We went through multiple examples for understanding the application of composition in C# coding.

Recommended Articles

This is a guide to Composition C#. Here we discuss the introduction, working of composition in C#, and examples, respectively. You may also have a look at the following articles to learn more –

You're reading Working And Examples Of Composition In C#

Working Of Predicate Delegate In C# With Examples

Introduction to C# Predicate

Web development, programming languages, Software testing & others

Syntax:

Where the object type is represented by P and obj is the object which compares the criteria that is defined within a method and is  represented by predicate delegate.

Working of Predicate Delegate in C#

A function that returns true or false is a predicate and the reference to a predicate is a predicate delegate.

The feature of predicate delegate was introduced with the release of .NET 2.0. framework.

The predicate function can be defined, and it can be passed as a parameter to any other function through predicate delegate.

A special case of Func is predicate delegate which takes only one parameter as input and it returns a Boolean value that is either true of false.

Any method can be written inside a predicate delegate even the expression of lambda or anonymous method.

A generic type is taken as an argument by the predicate delegate when it is used with the expression of lambda.

Examples of C# Predicate

Given below are the examples mentioned:

Example #1

C# program to demonstrate the use of predicate delegate in a program to check if the given string passed as a parameter is in capital letters or not.

Code:

using System; namespace program { public class check { static bool IsUC(string stri) { return stri.Equals(stri.ToUpper()); } static void Main(string[] args) { bool res = isU("welcome to c#"); Console.WriteLine(res); } } }

Explanation:

In the above program, a namespace called program is defined. Then a class called check is defined. Then a Boolean method is defined to check if the given string is written in capital letters or not. If the given string is written in capital letters, true is returned else False is returned. Then the main method is called.

Then a predicate delegate is defined with object type as string and IsUC is an object which compares the criteria that is defined within a method and is represented by predicate delegate. Then the result of the predicate delegate is stored in a variable called res. Then the result is displayed.

Example #2

C# program to demonstrate the use of predicate delegate in a program to check if the length of the given string is less than a specified value or not.

using System; class program { public delegate bool my_del(string stri); public static bool fun(string stri) { if (stri.Length < 5) { return true; } else { return false; } } static public void Main() { my_del obj = fun; Console.WriteLine(obj("Shobha")); } }

Output:

Explanation:

In the above program, a class called program is defined. Then a predicate delegate is defined with object type as string. Then a method is defined inside a predicate delegate by passing the object as parameter to check if the length of the given string is less than a specified value. If the length of the string is less than the given specified value, true is returned else false is returned.

Then the Main method is called. Then a predicate delegate is defined with object type as string and fun is an object which compares the criteria that is defined within a method and is represented by predicate delegate. Then the string to be passed as a parameter to predicate delegate is written at last.

Advantages

The Predicate delegates are useful when we have to filter out a list of values.

The predicate delegates can be made inline for one off search function.

The predicate delegates can be used when we have to search for items in a generic collection.

By using predicate delegates, the length of the code is shortened and either true or false is returned.

Anonymous methods, expression of lambda can be assigned to predicate delegates.

The predicate delegates provide the logic at runtime and it can be a simple logic or complicated logic.

Recommended Articles

Working And Examples Of Numpy Axis Function In Python

Introduction to NumPy axis

Web development, programming languages, Software testing & others

Syntax:

NumPy.function(arrayname, axis = 0/1)

Where NumPy.function is any function on which the axis function must be applied, arrayname is the name of the array on which the NumPy.function must be performed along the axis specified by axis function whose value can be either 0 or 1.

Working of axis function in NumPy

The directions along the rows and columns in a two-dimensional array are called axes in NumPy.

The direction along the rows is axis 0 and is the first axis that runs down the rows in multi-dimensional arrays.

The direction along the columns is axis 1 and is the second axis which runs across the columns in multi-dimensional arrays.

The axes in NumPy are numbered, beginning from zero.

One should always be alert on what parameters are passed to the axis function and how they impact the function on which they are used, and the axis function in NumPy can be used on several functions.

Examples

Different examples are mentioned below:

Example #1

Python program to demonstrate NumPy axis function to create an array using array function and find the sum of the elements of the array along the axis = 0 and along the axis = 1:

#we are importing the package NumPy as num import numpy as num #creating a two dimensional array using array function and storing it in a avariable called array1 array1 = num.array([[1,2,3],[4,5,6]]) #displaying the elements of newly created array print("The elements of the newly created array are:") print(array1) #using axis function on the newly created array along with sum function to find the sum of the elements of the array along the axis = 0 arraysum = num.sum(array1, axis = 0) print("n") #displaying the sum of the elements of the array along the axis = 0 print("The sum of the elements of the newly created array along the axis = 0 are:") print(arraysum) print("n") #using axis function on the newly created array along with sum function to find the sum of the elements of the array along the axis = 1 arraysum1 = num.sum(array1, axis = 1) #displaying the sum of the elements of the array along the axis = 1 print("The sum of the elements of the newly created array along the axis = 1 are:") print(arraysum1)

Output:

In the above program, the package NumPy is imported as num to be able to make use of array function, sum function, and axis function. Then a two-dimensional array is created using the array function and stored in a variable called array1. Then the elements of the array array1 are displayed. Then sum function is used on the array array1 to find the sum of the elements of the array along axis = 0, and the result is displayed as the output on the screen; then again sum function is used on the array array2 to find the sun of the elements of the array along axis = 1 and the result is displayed as the output on the screen. The output is shown in the snapshot above.

Example #2

Python program to demonstrate NumPy axis function to create an array using array function and find the sum of the elements of the array along the axis = 0 and along the axis = 1:

#we are importing the package NumPy as num import numpy as num #creating a two dimensional array using array function and storing it in a avariable called array1 array1 = num.array([[5,4,3],[2,1,0]]) #displaying the elements of newly created array print("The elements of the newly created array are:") print(array1) #using axis function on the newly created array along with sum function to find the sum of the elements of the array along the axis = 0 arraysum = num.sum(array1, axis = 0) print("n") #displaying the sum of the elements of the array along the axis = 0 print("The sum of the elements of the newly created array along the axis = 0 are:") print(arraysum) print("n") #using axis function on the newly created array along with sum function to find the sum of the elements of the array along the axis = 1 arraysum1 = num.sum(array1, axis = 1) #displaying the sum of the elements of the array along the axis = 1 print("The sum of the elements of the newly created array along the axis = 1 are:") print(arraysum1)

Output:

In the above program, the package NumPy is imported as num to be able to make use of array function, sum function, and axis function. Then a two-dimensional array is created using the array function and stored in a variable called array1. Then the elements of the array array1 are displayed. Then sum function is used on the array array1 to find the sum of the elements of the array along axis = 0, and the result is displayed as the output on the screen; then again sum function is used on the array array2 to find the sun of the elements of the array along axis = 1 and the result is displayed as the output on the screen. The output is shown in the snapshot above.

Recommended Articles

This is a guide to the NumPy axis. Here we discuss the concept of the NumPy axis function in Python through definition, syntax, and the working of axis function in python through programming examples and outputs. You may also have a look at the following articles to learn more –

Rule Of Thirds: The Composition Rules

When it comes to presenting the story, we need to start with the layout. This is where the rule of thirds comes into play. What is the rule of thirds? The rule of thirds is a data storytelling method of arranging the elements within a composition.

If we divide the frame with two vertical lines and two horizontal lines, we end up with nine boxes.

The idea is to align the points of interest along the vertical lines or where the lines intersect to come up with a more pleasing, and balanced composition.

This rule of composition is highly used in photography, video, and cinema.

In fact, during the Renaissance, they started to use this when new styles of painting emerge. The objective is to tell richer, and more complex stories.

Contrary to what they used before, the main character or main point of interest was placed in the center. When you have the subject in the center of the frame, there is an equal distance in all directions, which tends to make the size static with no movements and no interaction.

They discovered that they can showcase more of the background and create more conversation by taking the subject out of the center and moving it along to one of these intersecting lines in the frame.

There are nine equal blocks that we can divide with four intersecting points. Placing your subjects within these four intersecting points creates more dynamic communication.

When you take the point of interest and move it to one of these intersection lines, it creates more of a dynamic image. It allows the eyes to come into the frame, look at the object, look at the background, have a more natural flow, and connect to what they see.

One of the concepts or theories behind framing allows us to create more dynamic images.

This painting by Valentin de Boulogne shows how the main character is all placed at the upper defining line, creating a dynamic arrangement of figures.

The ‘Eye Flow‘ is another great use of the rule of thirds in this painting by Rubens. The main focal point of the board is placed at an intersection, and the secondary point of interest follows intersections as well.

Without a doubt, the rule of thirds can be very useful when creating reports as well.

Let’s take a look at this report that I created inside Power BI. We see how the use of the rule of thirds points to the helmet of Hamilton.

One of the main ideas of the rule of thirds is creating a connection with a viewer and telling the story by anticipating or controlling how the eyes will move from one part of the screen to another.

According to the rule of thirds, we know how the eyes are scanning a particular image or painting, which is why we divide our report.

In addition, the box’s position is hugely important in the order and the way the user will interact. We generally give more focus to the top left corner of any visuals or design.

First, we look at the top left spot and gradually move to the right corner, then we continue by performing a sort of ‘Z.’ We give the least attention to the bottom right spot.

This is the visual distribution for our eyes.

This is the primary reason we usually place the KPIs or filters on the top part or left part of the screen, and the title on the top left.

In summary, the designer can highly influence the way the user looks at the report by using color, shapes, size, space, and orientation of elements.

Grid placement should be evident in report design because it’s the way the report is consumed by the viewer. Lastly, consider how you place your visuals and pay attention to the size of the visual spaces, and the alignment.

All the best,

Alex

Print All Subsequences Of A String In C++

In this problem, we are given a string and we have to print all the subsequences of the string. The substring generated is created by deleting the elements of the string but the order remains the same(i.e. Order cannot be changed).

Let’s take an example to understand the topic better −

Input: xyz Output: x,y,z,xy,yz,xz,xyz

Explanation − In the above example, we can see the only characters are deleted to create substring. No, rearranging takes place.

There can be multiple methods to solve this problem, here we will discuss a few of them to understand methods.

One is by selecting elements of the string and eliminating a few to create a sequence. In this method, we will pick a few elements and delete the rest to create the substring.

Example import java.util.*; class Main{    public static void main(String[] args) {       String s="pqrs";       System.out.println("All the substring found are :");       findSubString(s,"");       System.out.println(subStringSeq);    }    public static void findSubString(String s, String ans) {       if(s.length()==0){          subStringSeq.add(ans);          return;       }       findSubString(s.substring(1),ans+s.charAt(0)) ;       findSubString(s.substring(1),ans);    } } Output

All the substring found are −

[pqrs, pqr, pqs, pq, prs, pr, ps, p, qrs, qr, qs, q, rs, r, s, ]

Another method could be iterating over the string and generate substring. And dropping characters of the sequence to generate substrings. Here, we will use a list to store the substrings. And check if the sequence found is already found or not.

Example import java.util.HashSet; public class Main{    static void findSubString(String str){       for (int i = 0; i < str.length(); i++) {             String sub_str = str.substring(i, j);             if (!subString.contains(sub_str))                subString.add(sub_str);             for (int k = 1; k < sub_str.length() - 1; k++) {                StringBuffer sb = new StringBuffer(sub_str);                sb.deleteCharAt(k);                if (!subString.contains(sb));                   findSubString(sb.toString());             }          }       }    }    public static void main(String[] args){       String s = "pqrs";       System.out.println("The subsequence is ");       findSubString(s);       System.out.println(subString);    } } Output

The subsequence is

[rs, pq, qr, pr, qs, ps, prs, p, pqr, q, r, s, pqs, qrs, pqrs]

One more method can be fix characters and find substring. In this method we will fix elements of the string one by one and using these fixed characters, we will find the subsequence. Recursive calling of this method creates the required string subsequence.

Example class Main {    static void subString(String str, int n,    int index, String curr){       if (index == n){          return;       }       System.out.print(curr + ", ");       for (int i = index + 1; i < n; i++){          curr += str.charAt(i);          subString(str, n, i, curr);          curr = curr.substring(0, curr.length() - 1);       }    }    static void printSubStrings(String str){       int index = -1;       String curr = "";       subString(str, str.length(), index, curr);    }    public static void main(String[] args){       String str = "pqrs";       System.out.println("The subStrings are :") ;       printSubStrings(str);    } } Output

The subStrings are −

p, pq, pqr, pqrs, pqs, pr, prs, ps, q, qr, qrs, qs, r, rs, s

Prerequisite For Using Gst In Tallyprime (Composition)

 PDF

GST Composition Scheme

Composition scheme under GST is a relief mechanism for small taxpayers as it offers comparatively lesser compliance activity, as well as a flat GST tax rate.  As a Composite dealer, you can make payments and file taxes quarterly, instead of monthly. The tax rate varies from 1% to 5% on the total turnover and you cannot claim Input Tax Credit. There are several other eligibility criteria to opt for GST Composition Scheme, to learn more, refer to our blog.

Composition Scheme Rules

Composition scheme under GST is different from the regular GST scheme and has its own set of rules and intimation for dealers. For instance, taxpayers supplying Exempt supplies, suppliers of services other than restaurant-related services, manufacturers of ice cream, pan masala, or tobacco, businesses that supply goods through an e-commerce operator, and so on, cannot opt for the Composition scheme under GST. Also, no Input Tax Credit can be claimed and no Inter-state supply of goods can be done by a Composite Dealer, to learn more refer to our blog.

Who is a Composite Dealer under GST

Under the GST Composition scheme, the department has certain limitations and restrictions for a Composite Dealer. There are tax collection limitations, a specified GST rate and GST Returns period, and a GST invoice format that has to be followed and maintained by the dealer under the GST Composition scheme. As a Composite Dealer, one cannot interstate outward supplies of goods, cannot avail the credit of input tax paid on inward supplies, shall not issue a tax invoice, and shall only issue a BILL OF SUPPLY, and so on. To learn more about Composite Dealer under GST, refer to our blog.

GST Composition Scheme for Services

 Similarly, to register as a Composite Dealer in the case of a services business, the required turnover is less than INR 50 Lakhs. However, under the GST composition scheme for services, only the supplier of restaurant-related services can be registered as a Composit Dealer. Service provided by restaurants by way of or as part of any service or in any other manner whatsoever of goods, being food or any other article for human consumption of any drink (other than alcoholic liquor for human consumption) is leviable at the rate of 5% percent (2.5% of CGST and 2.5% for SGST) under Composition scheme. To learn more about GST Composition Scheme for Services, refer to our blog.

Understand GST Rates for Composition Scheme

Since the GST Composition scheme is for small taxpayers, the GST rates defined under this scheme differ from the regular GST scheme. For a Composite dealer, the tax rate varies from 1% to 5% on the total turnover and you can make payments and file taxes quarterly, instead of monthly.   To learn more about GST Rates for Composition Scheme, refer to our blog.

How to Switch to Composition Scheme

GST composition scheme is a scheme for payment of GST available to small taxpayers whose aggregate turnover in the preceding financial year did not cross the set limit of INR 1.5 Crores and INR 75 Lakhs in special category states. If you are a regular GST dealer, you can easily switch to the GST composition scheme by filing intimation forms with the government.  This intimation must be given at the beginning of every Financial Year by a dealer wanting to opt for the Composition Scheme. Also, there are certain criteria to meet in terms of the stock held, available ITC, and so on for the transition from regular to composition. To learn more about Switch to Composition Scheme. refer to our blog.

Set Up TallyPrime for GST Composition

Purchases Under Composition GST

Sales Under Composition GST

GST CMP-08 Report

GSTR-4 Report

File GSTR-9A

GSTR-4 Annual Returns

Update the detailed information about Working And Examples Of Composition In C# on the Bellydancehcm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!