Page 1 of 1

// 〖Anytime the Cat cry "Miao~" and the Mouse ran away immediately.〗 // According to the decibel (10~100db) at which

Posted: Fri Jul 01, 2022 5:35 am
by answerhappygod
// 〖Anytime the Cat cry "Miao~" and the Mouse ran away immediately.〗
// According to the decibel (10~100db) at which the cat's cries, the mouse runs away at a corresponding speed(10~100db)
// escaping velocity (int: m/s) v = ((db/40) + 1) * 4
public class TestCatCall { public static void Main() {
Cat c1 = new Cat("big yellow cat");
Cat c2 = new Cat("Kitten");
Mouse m1 = new Mouse("guinea pig");
Mouse m2 = new Mouse("big squirrel");
c2.Calling += m1.Escape; //★
c2.Calling += m2.Escape; //★
int db;
do {
Console.WriteLine("Please input an integer between 10 and 100: (illegal data to exit)");
Int32.TryParse(Console.ReadLine(), out db); if(db < 10 || db > 100) break;
c1.Call(db); //★
c2.Call(db); //★
} while (true);
} // END of Main method
}
class Mouse {
public string Name { get; set; }
private int EscV; //Escaping velocity (m/s) public Mouse(string name) { Name = name; }
public void Escape(object sender, Cat.SoundDbEventArgs e) {
//★
EscV = ((e.Db / 40) + 1) * 4;
Console.WriteLine("The mouse {0} is running away at a speed of {1} m/s!", Name, EscV);
}
}
【Task】Provide the code for the Cat class to meet the required functions.
【Technical Requirements】
① Use the event model based on delegate;
② Publishers need to pass parameters to subscribers.
One of the runtime screenshot is given below.
Anytime The Cat Cry Miao And The Mouse Ran Away Immediately According To The Decibel 10 100db At Which 1
Anytime The Cat Cry Miao And The Mouse Ran Away Immediately According To The Decibel 10 100db At Which 1 (11.53 KiB) Viewed 32 times
C\Windows\System32\cmd.exe D:\www\Spring2022>Temp Please input an integer between 10 and 100: (illegal data to exit) 50 Cat is crying... NULL for's Calling event! Cat is crying.... □ X There' re 2 subscribers for The mouse The mouse 's Calling event! is running away at a speed of 8 m/s! is running away at a speed of 8 m/s! Please input an integer between 10 and 100: (illegal data to exit) -100 D:\www\Spring2022>