+ 4

Seeking experts in Overloading Operator - Dance Module Project

I am having hardtime understanding overloading operator. Here i did, using the examples giving but i am outputting any results/ using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string name1 = Console.ReadLine(); int points1 = Convert.ToInt32(Console.ReadLine()); string name2 = Console.ReadLine(); int points2 = Convert.ToInt32(Console.ReadLine()); DancerPoints dancer1 = new DancerPoints(name1, points1); DancerPoints dancer2 = new DancerPoints(name2, points2); DancerPoints total = dancer1 + dancer2; Console.WriteLine(total.name); Console.WriteLine(total.points); } } class DancerPoints { public string name; public int points; public DancerPoints(string name, int points) { this.name = name; this.points = points; } //overload the + operator public static DancerPoints operator+ (DancerPoints a, DancerPoints b) { string name = a.name + "&" + b.name; int points = a.points + b.points; DancerPoints res = new DancerPoints(name, points) return res; } } }

6th Jan 2021, 5:58 AM
Faris Mohamed
Faris Mohamed - avatar
14 Answers
+ 10
Hi again! There are two errors. 1. Missing semicolon after DancerPoints res = new DancerPoints (name, points) ; 2. If look closely at the example then the output is (name1) + space + & + space + (name2) But you wrote string name = a.name + "&" + b.name ; which didn't print the required space. Modify it to string name = a.name + " & " + b.name ; p.s. Try to read the compiler error and also try to match your output with the required output. Then you can easily find this errors.
6th Jan 2021, 6:07 AM
Minho
Minho - avatar
+ 14
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string name1 = Console.ReadLine(); int points1 = Convert.ToInt32(Console.ReadLine()); string name2 = Console.ReadLine(); int points2 = Convert.ToInt32(Console.ReadLine()); DancerPoints dancer1 = new DancerPoints(name1, points1); DancerPoints dancer2 = new DancerPoints(name2, points2); DancerPoints total = dancer1 + dancer2; Console.WriteLine(total.name); Console.WriteLine(total.points); } } class DancerPoints { public string name; public int points; public DancerPoints(string name, int points) { this.name = name; this.points = points; } //overload the + operator public static DancerPoints operator+ (DancerPoints a, DancerPoints b) { string name = a.name + " & " + b.name ; int points = a.points + b.points; DancerPoints res = new DancerPoints (name, points) ; return res; } } }
7th Feb 2021, 5:19 PM
Md Momin Uddin Hridoy
Md Momin Uddin Hridoy - avatar
+ 8
I'm not talking about any other ide then Sololearn compiler.. ๐Ÿ˜… The message's are easy enough to read. Also no ide can tell you about the 2nd error I mentioned, than SL compiler. You're most welcome ๐Ÿ˜Š
6th Jan 2021, 6:12 AM
Minho
Minho - avatar
+ 6
Hey... Missing semi-colon and typos are most popular compile time errors ๐Ÿ˜†๐Ÿ‘ No matter how much you learn there will be always one semi colon which you'll forgot ๐Ÿ˜†๐Ÿ˜‚ I'm also glad that I could help ๐Ÿ™
6th Jan 2021, 6:18 AM
Minho
Minho - avatar
+ 2
wow! thanks again minho! Sometimes it is difficult to debug my own errors unlike those on IDE. there's information to know which line of code has errors. thanks again!!!!!
6th Jan 2021, 6:11 AM
Faris Mohamed
Faris Mohamed - avatar
+ 1
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string name1 = Console.ReadLine(); int points1 = Convert.ToInt32(Console.ReadLine()); string name2 = Console.ReadLine(); int points2 = Convert.ToInt32(Console.ReadLine()); DancerPoints dancer1 = new DancerPoints(name1, points1); DancerPoints dancer2 = new DancerPoints(name2, points2); DancerPoints total = dancer1 + dancer2; Console.WriteLine(total.name); Console.WriteLine(total.points); } } class DancerPoints { public string name; public int points; public DancerPoints(string name, int points) { this.name = name; this.points = points; } //overload the + operator public static DancerPoints operator + (DancerPoints a, DancerPoints b){ string nm = a.name+" & "+b.name; int pt = a.points+b.points; DancerPoints dp = new DancerPoints(nm,pt); return dp; } } }
12th Apr 2021, 4:53 PM
Shahed Mohammad Hridoy
Shahed Mohammad Hridoy - avatar
0
Dance In a ballroom dancing competition, each dancer from a pair is evaluated separately, and then their points are summed up to get the total pair score. The program you are given takes the names and the points of each dancer as input and creates a DancerPoints objects for each dancer, using the taken name and score values as parameters for constructors. Complete the given class, using overload + operator to return an new object where the names of dancers are in one string (see sample output) and the score is equal to the sum of their points. The declaration of that object and the output of its points are already written in Main(). Sample Input Dave 8 Jessica 7 Sample Output Dave & Jessica 15
6th Jan 2021, 5:59 AM
Faris Mohamed
Faris Mohamed - avatar
0
yeah i know. from the missing semicolom. i could see the result, and ammend it. But i think thatโ€™s not the way to learn it. Really appreciate your help Minho!
6th Jan 2021, 6:15 AM
Faris Mohamed
Faris Mohamed - avatar
0
I stuck in same project and I don't understand how I am gonna make 3 different values in to the same operator ?
6th Mar 2021, 10:45 PM
OmerPasa3328
OmerPasa3328 - avatar
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string name1 = Console.ReadLine(); int points1 = Convert.ToInt32(Console.ReadLine()); string name2 = Console.ReadLine(); int points2 = Convert.ToInt32(Console.ReadLine()); DancerPoints dancer1 = new DancerPoints(name1, points1); DancerPoints dancer2 = new DancerPoints(name2, points2); DancerPoints total = dancer1 + dancer2; Console.WriteLine(total.name); Console.WriteLine(total.points); } } class DancerPoints { public string name; public int points; public DancerPoints(string name, int points) { this.name = name; this.points = points; } //overload the + operator public static DancerPoints operator + (DancerPoints a, DancerPoints b){ string nm = a.name+" & "+b.name; int pt = a.points+b.points; DancerPoints dp = new DancerPoints(nm,pt); return dp; } } }
25th Apr 2021, 10:42 AM
Md. Rakibul Islam
Md. Rakibul Islam - avatar
0
My solution compiles with error: Error CS7036 There is no argument given that corresponds to the required formal parameter 'name' of 'Program.DancerPoints.DancerPoints(string, int)' Could you tell me please why? using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string name1 = Console.ReadLine(); int points1 = Convert.ToInt32(Console.ReadLine()); string name2 = Console.ReadLine(); int points2 = Convert.ToInt32(Console.ReadLine()); DancerPoints dancer1 = new DancerPoints(name1, points1); DancerPoints dancer2 = new DancerPoints(name2, points2); DancerPoints total = dancer1 + dancer2; Console.WriteLine(total.name); Console.WriteLine(total.points); } } class DancerPoints { public string name; public int points; public DancerPoints(string name, int points) { this.name = name; this.points = points; } //overload the + operator public static DancerPoints operator+ (DancerPoints _dancer1, DancerPoints _dancer2) { return new DancerPoints { name = _dancer1.name.ToString() + " & " + dancer2.name.ToString(), points = _dancer1.points + _dancer2.points }; } } }
23rd Jun 2022, 9:40 AM
ะะฝั‚ะพะฝ ะ›ะตะพะฝั‚ัŒะตะฒ
0
using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string name1 = Console.ReadLine(); int points1 = Convert.ToInt32(Console.ReadLine()); string name2 = Console.ReadLine(); int points2 = Convert.ToInt32(Console.ReadLine()); DancerPoints dancer1 = new DancerPoints(name1, points1); DancerPoints dancer2 = new DancerPoints(name2, points2); DancerPoints total = dancer1 + dancer2; Console.WriteLine(total.name); Console.WriteLine(total.points); } } class DancerPoints { public string name; public int points; public DancerPoints(string name, int points) { this.name = name; this.points = points; } //overload the + operator public static DancerPoints operator+ (DancerPoints a, DancerPoints b) { string name = a.name + " & " + b.name ; int points = a.points + b.points; DancerPoints res = new DancerPoints (name, points) ; return res; } } }
11th Aug 2023, 6:49 PM
Parthasarathi Panda
Parthasarathi Panda - avatar