2
Answers

Problem to deal with private access modifier

Since the variables are private than why it show no error on compiling because we call a private members  (highlighted) from another class. i know about get and set but here we use get set only for private string courseName.
 
 
using System;
public class GradeBook
{
private string courseName;
private int total;
private int gradeCounter;
private int aCount;
private int bCount;
private int cCount;
private int dCount;
private int fCount;
public string CourseName
{
get
{
return courseName;
}
set
{
courseName = value;
}
}
public GradeBook(string name)
{
CourseName = name;
}
public void DisplayMessage()
{
Console.WriteLine("Welcome to the {0}",CourseName);
}
public void InputGrade()
{
int grade;
string input;
Console.WriteLine("{0}\n{1}","Enter the grade in the Range (0-100): ", "Type ctrl+z and press enter to terminate the input");
input=Console.ReadLine();
while(input !=null)
{
grade = Convert.ToInt32(input);
total += grade;
gradeCounter++;
IncreamentLetterGradeCounter(grade);
input = Console.ReadLine();
}
}
private void IncreamentLetterGradeCounter(int grade)
{
switch(grade/10)
{
case 9:
case 10:
aCount++;
break;
case 8:
bCount++;
break;
case 7:
cCount++;
break;
case 6:
dCount++;
break;
default:
fCount++;
break;
}//end of switch
}//end of method increament letter grade counter
public void DisplayGradeReport()
{
Console.WriteLine("Grade Report: ");
if (gradeCounter != 0)
{
double average = (double)(total / gradeCounter);
Console.WriteLine("Total of the {0} grades enter is {1}", gradeCounter, total);
Console.WriteLine("The average of class is {0:F2}", average);
Console.WriteLine("{0}A: {1}\nB: {2}\nC: {3}\nD: {4}\nF: {5}", "Number of students who recieved each grade: \n"
, aCount
, bCount
, cCount
, dCount
, fCount);
}
else
Console.WriteLine("No grades were entered");
}
}
 
 
 
 
 
 #####ANOTHER CLASS#########
using System;
class GrdaeBookTest
{
public static void Main()
{
GradeBook myBook = new GradeBook("Introduction to C#");
myBook.DisplayMessage();
myBook.InputGrade();
myBook.DisplayGradeReport();
Console.ReadLine();
}
}




Answers (2)
0
Mahesh Chand
2 286.9k 123.7m 14y
If you build a Web application in ASP.NET, it can be browse from any of these mobile devices using a Web browser (all of them have a Web browser).

But if you want to build applications for iPhone, and other mobile devices, you need to use their SDKs. For example, you need to use Mono Touch to build iPhone applications and andriod SDK to build droid applications.

Here are more readings on Mono Touch. See Blogs.

Mono Touch