You are on page 1of 3

Code Writing

1. Sac County:
Write a program, in any language you prefer, that prints the numbers from 1 to 100. But
for multiples of three print "Sac" instead of the number, and for the multiples of five
print "County". For numbers which are multiples of both three and five print
"SacCounty".
Answer public void
PrintMultiplesOfThreeAndFive()
{
for (int i = 1; i <= 100; i++)
{
if (i % 15 == 0)
Console.WriteLine("SacCounty");
else if (i % 3 == 0)
Console.WriteLine("Sac");
else if (i % 5 == 0)
Console.WriteLine("County");
else
Console.WriteLine(i);

}
}

2. ASP.NET MVC
Create a web service controller that allows the origin http://www.saccounty.net to
access it using CORS attributes with a method that returns a person object.
public class Person
{
public int Id { get; set; } public string Code { get; set; }
public string Name { get; set; }
}

[EnableCors(origins: " http://www.saccounty.net", headers: "*", methods: "*")]


public class TestController : ApiController
{

public IActionResult GetPerson()


{
Person person = new Person
{
Id = 10,
Code = "test",
Name = "test"
}; return
Ok(person);
}
}
3. SQL
Given the following Entity Relationship Diagram (ERD):

Create a SQL User-Defined Function called AuthorizeProject that takes parameters for the ProjectID and
the SystemsUserID, and returns a bit representing whether the user is authorized (as a PM) for the given
project. In order to be authorized as a PM, the user must be a current member of the project and the
must have at least one role that includes PM authority (Boolean field isPMRole = true).
Answer

create function AuthorizeProject


(
@ProjectID INT,
@SystemsUserID INT
)
RETURNS BIT
AS
BEGIN RETURN(SELECT 1 FROM [Project] p INNER JOIN [ProjectMenber] pm on p.ProjectID=pm.ProjectID
INNER JOIN [ProjectUser] pu on pu.SystemUserID=p.SystemUserID
INNER JOIN [ProjectRole] pr on pr.RoleID=pm.RoleID
WHERE p.ProjectID=@ProjectID && pm.SystemUserID=@SystemUserID && pu.SystemUserID=@SystemUserID &&
pr.isPMRole=1)
END
4. Replace the missing code parts (<<A>>) to make a function that takes a string
as an argument and returns the number of vowels in that string. Give an
example of how to call that function.
const findVowels = str => { let
count = 0; const vowels =
"aeiou"; for(let char of str) {
if(vowels.indexOf(char) !== -1) {
count++;
}
}
return count;
}

You might also like