This program is compiling well but message box says there were build errors. Please anyone can explain the reason.
using System;
public class CreateStudent
{
public static void Main()
{
Student oneSophomore = new Student();
oneSophomore.SetId(951);
oneSophomore.SetName("Ross");
oneSophomore.SetGPA(3.5);
Console.WriteLine
("The student named {0} has ID # is {1} and a gpa of {2}",
oneSophomore.GetName(), oneSophomore.GetId(), oneSophomore.GetGPA());
Console.ReadLine();
}
}
class Student
{
private int idNumber;
private string lastName;
private double gradePointAverage;
public int GetId()
{
return idNumber;
}
public void SetId(int id)
{
idNumber = id;
}
public int GetName()
{
return lastName;
}
public void SetName(string name)
{
lastName = name;
}
public double GetGPA();
{
return gradePointAverage;
}
public void SetGPA(double gpa);
{
gradePointAverage = gpa;
}
}
//The student named Ross has ID # is 951 and a gpa of 3.5
Loading
Satyapriya NayakPosted Nov 29, 2011, 1:19 PM
Your mistake is public double GetGPA();
Repalce public double GetGPA(); with public double GetGPA()
Note :- semicolon(;)
Your solution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
//class Program
//{
// static void Main(string[] args)
// {
// }
//}
public class CreateStudent
{
public static void Main()
{
Student oneSophomore = new Student();
oneSophomore.SetId(951);
oneSophomore.SetName("Ross");
oneSophomore.SetGPA(3.5);
Console.WriteLine("The student named {0} has ID # is {1} and a gpa of {2}", oneSophomore.GetName(), oneSophomore.GetId(), oneSophomore.GetGPA());
Console.ReadLine();
}
}
class Student
{
private int idNumber;
private string lastName;
private double gradePointAverage;
public int GetId()
{
return idNumber;
}
public void SetId(int id)
{
idNumber = id;
}
public string GetName()
{
return lastName;
}
public void SetName(string name)
{
lastName = name;
}
public double GetGPA()
{
return gradePointAverage;
}
public void SetGPA(double gpa)
{
gradePointAverage = gpa;
}
}
}
Thanks
Posted Jan 9, 2012, 3:55 PM
VulpesPosted Jan 9, 2012, 3:26 PM
So just make sure that you've closed the previous instance before you do this.
Posted Jan 9, 2012, 2:53 PM
Error generating Win32 resource: The process cannot access the file because it is being used by another process.
VulpesPosted Nov 29, 2011, 1:59 PM
Unbelievably, I aleady had another program called CreateStudent.cs on my machine, copied yours to CreateStudent2.cs, got distracted and then compiled and ran the first version (which, of course, worked fine) rather than your program! Sorry about that.
Posted Nov 29, 2011, 1:53 PM
Posted Nov 29, 2011, 1:45 PM
I use Microsoft Visual C# 2010 Express, a free download from Microsoft this may produce error message if the program is in the Traditional method. Modified version of this program did not producing any error message. What you think?
Modified version as follows:
using System;
public class CreateStudent
{
public static void Main()
{
Student oneSophomore = new Student();
oneSophomore.Id = 951;
oneSophomore.Name = "Ross";
oneSophomore.GPA = 3.5;
Console.WriteLine
("The student named {0} has ID # is {1} and a gpa of {2}",
oneSophomore.Name, oneSophomore.Id, oneSophomore.GPA);
Console.ReadKey();
}
}
class Student
{
private int idNumber;
private string lastName;
private double gradePointAverage;
public int Id
{
get { return idNumber; }
set { idNumber = value; }
}
public string Name
{
get { return lastName; }
set { lastName = value; }
}
public double GPA
{
get { return gradePointAverage; }
set { gradePointAverage = value; }
}
}
//The student named Ross has ID # is 951 and a gpa of 3.5
VulpesPosted Nov 29, 2011, 1:02 PM
I'd check your files in Solution Explorer and, if program.cs is present, just delete it and rebuild.
Posted Nov 29, 2011, 12:56 PM
Error2Invalid token ';' in class, struct, or interface member declarationC:\Documents and Settings\User\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs4533Get Set traditinal method
Error3Expected class, delegate, enum, interface, or structC:\Documents and Settings\User\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs4712Get Set traditinal method
Error4Type or namespace definition, or end-of-file expectedC:\Documents and Settings\User\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs511Get Set traditinal method
VulpesPosted Nov 29, 2011, 12:48 PM
What build errors are being reported?