(FOR C #) A class called Company is to be defined as illustrated in the class diagram. It contains two data members: name (of type string) and salary (of type int); and three member functions: getName(), getSalary (), and getEmployee().
Three instances of Company called s1, s2, and s3 shall then be constructed with their respective data members, as shown in the instance diagrams.
Company
-name:string=”Cube”
-salary:int=470000000
+Company()
+Company(n:string)
+Company(n:string, s:int)
+getName():string
+getSalary():int
+getEmployee():int
S3 - Contractor
-name:string=”Jake”
-salary:int=1800
+ getName()
+ getSalary ()
+ getEmployee()
Objects
S1 - Employee
-name:string=”Mark”
-salary:int=1900
+ getName()
+ getSalary ()
+ getEmployee()
S2 - Manager
-name:string=”Kai”
-salary:int=1700
+ getName()
+ getSalary ()
+ getEmployee()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
Company s1 = new Company("Mark", 1900);
Company s2 = new Company("Kai", 1800);
Company s3 = new Company("Jake", 1700);
Console.WriteLine(s1.GetName());
Console.WriteLine(s1.GetSalary());
Console.WriteLine(s1.GetEmployee());
Console.WriteLine(s2.GetName());
Console.WriteLine(s2.GetSalary());
Console.WriteLine(s2.GetEmployee());
Console.WriteLine(s3.GetName());
Console.WriteLine(s3.GetSalary());
Console.WriteLine(s3.GetEmployee());
}
}
public class Company
{
string name;
int salary;
public Company()
{
}
public Company(string name, int salary)
{
this.name = name;
this.salary = salary;
}
public Company(string name) : this(name, 0)
{
}
public string GetName()
{
return name;
}
public int GetSalary()
{
return salary;
}
public int GetEmployee()
{
return 1;
}
}
}
Comments
Leave a comment