How do I do this WITHOUT the use of a \"USING\" statement or call to a writeline
ID: 3846869 • Letter: H
Question
How do I do this WITHOUT the use of a "USING" statement or call to a writeline??
All answers so far have used both??
Code the Grades project from Exercise 3-1, such that you obtain exactly the same output, including formatting/positioning, WITHOUT including the "using" keyword OR any calls to Writeline.
HINT: "System.XYZ…." accesses class “XYZ” within the namespace “System”.
using System;
class Grades { public static void Main( string[] args)
{ const float MIDTERM_PERCENTAGE = .25F;
const float FINALEXAM_PERCENTAGE = .25F;
const float RESEARCH_PERCENTAGE = .30F;
const float PRESENTATION_PERCENTAGE = .20F;
int midterm = 70;
int finalExGrade = 80;
int research = 90;
int presentation = 100;
float finalNumericGrade = 0;
finalNumericGrade = (midterm * MIDTERM_PERCENTAGE) + (finalExamGrade * FINALEX_PERCENTAGE) + (research * RESEARCH_PERCENTAGE) + (presentation * PRESENTATION_PERCENTAGE);
Console.WriteLine(" Midterm grade is : " + midterm);
Console.WriteLine(" Final Ex grade is : " + finalExamGrade);
Console.WriteLine(" Research grade is : " + research);
Console.WriteLine(" Presentation grade is: " + presentation);
Console.WriteLine(" nThe final grade is: " + finalNumericGrade); } }
}
using System;
namespace UserDefined{
class Display
{
public void func(str)
{
Console.WriteLine(str);
}
}
}
Explanation / Answer
From the question, I understand that instead of using built in function, you need to use the func() defind in Display() class in UserDefined namespace.
To do that,
1. Remove the using System; line before the class Grades
2. Use the following code for class Grades
class Grades {
public static void Main( string[] args)
{
const float MIDTERM_PERCENTAGE = .25F;
const float FINALEXAM_PERCENTAGE = .25F;
const float RESEARCH_PERCENTAGE = .30F;
const float PRESENTATION_PERCENTAGE = .20F;
int midterm = 70;
int finalExGrade = 80;
int research = 90;
int presentation = 100;
float finalNumericGrade = 0;
finalNumericGrade = (midterm * MIDTERM_PERCENTAGE) + (finalExamGrade * FINALEX_PERCENTAGE) + (research * RESEARCH_PERCENTAGE) + (presentation * PRESENTATION_PERCENTAGE);
UserDefined.Display.func(" Midterm grade is : " + midterm);
UserDefined.Display.func(" Final Ex grade is : " + finalExamGrade);
UserDefined.Display.func(" Research grade is : " + research);
UserDefined.Display.func(" Presentation grade is: " + presentation);
UserDefined.Display.func(" nThe final grade is: " + finalNumericGrade);
}
}
===================
In the above code, we are calling the func() in class Display from namespace UserDefined. This is done as UserDefined.Display.func( ... )
Please post a comment if you have any doubts. I shall respond to it. Please don't forget to rate the answer if it helped. Thank you very much.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.