Photo AI

Die slimskakelaars [Smart switches] is digitaliseerbare huisstoflikeerders en is simboliseer - NSC Information Technology - Question 3 - 2023 - Paper 1

Question icon

Question 3

Die-slimskakelaars-[Smart-switches]-is-digitaliseerbare-huisstoflikeerders-en-is-simboliseer-NSC Information Technology-Question 3-2023-Paper 1.png

Die slimskakelaars [Smart switches] is digitaliseerbare huisstoflikeerders en is simboliseer. Die program wat geskep word, sal die toestelskakeling van die skakelaar... show full transcript

Worked Solution & Example Answer:Die slimskakelaars [Smart switches] is digitaliseerbare huisstoflikeerders en is simboliseer - NSC Information Technology - Question 3 - 2023 - Paper 1

Step 1

Skryf kode vir 'n konstruktor-metode wat die skakelaar-ID (switch ID), die toestelnaam en die regte datatipe (data type) aanvaar

96%

114 rated

Answer

Die konstruktor vir die SmartSwitch klas kan soos volg geskryf word:

public SmartSwitch(string switchID, string deviceName, float powerUsage) {
    this.SwitchID = switchID;
    this.Device = deviceName;
    this.PowerUsage = powerUsage;
    this.SwitchStatus = false;  // Default to false
}

Step 2

Skryf kode vir ‘n metode met die naam getSwitchId wat 'n string teruggegee het

99%

104 rated

Answer

Die getSwitchID metode kan soos volg geskryf word:

public string getSwitchId() {
    return this.SwitchID;
}

Step 3

Skryf kode vir die wysigingsmetode (mutator method) met die naam setSwitchStatus

96%

101 rated

Answer

Die setSwitchStatus metode kan as volg geskryf word:

public void setSwitchStatus(bool status) {
    this.SwitchStatus = status;
}

Step 4

Skryf kode vir die determineSwitchStatus-prosedure

98%

120 rated

Answer

Die determineSwitchStatus prosedure kan soos volg geskryf word:

public void determineSwitchStatus() {
    if (this.SwitchStatus)
        Console.WriteLine("Die skakelaar is aan (ON).");
    else
        Console.WriteLine("Die skakelaar is af (OFF).");
}

Step 5

Skryf kode vir die toString-funksie wat 'n string teruglewer

97%

117 rated

Answer

Die toString metode kan as volg geskryf word:

public override string ToString() {
    return string.Format("SwitchID: {0}, Device: {1}, PowerUsage: {2}, SwitchStatus: {3}",
                        this.SwitchID, this.Device, this.PowerUsage, this.SwitchStatus);
}

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;