01 - CO - Introduction To Visual Studio and C# - PracticeAssignments
01 - CO - Introduction To Visual Studio and C# - PracticeAssignments
Introduction Visual
Studio and C#
Quiz questions, practical assignments and
Contents
1 Quiz.........................................................................................................................................................3
1.1 Question 1......................................................................................................................................3
1.2 Question 2......................................................................................................................................3
1.3 Question 3......................................................................................................................................3
1.4 Question 4......................................................................................................................................3
1.5 Question 5......................................................................................................................................4
1.6 Question 6......................................................................................................................................4
1.7 Question 7......................................................................................................................................4
2 Practical assignments: Classes & Objects...............................................................................................5
2.1 Programming Assignment 1: Install Visual Studio..........................................................................5
2.1.1 Case description.........................................................................................................................5
2.2 Programming Assignment 2: Hello…..............................................................................................5
2.2.1 Case description.........................................................................................................................5
2.3 Programming Assignment 3: Odd or even......................................................................................5
2.3.1 Case description.........................................................................................................................5
2.4 Programming Assignment 4: Extend demo....................................................................................5
2.4.1 Case description.........................................................................................................................5
2.5 Programming Assignment 5: Multiplication table..........................................................................6
2.5.1 Case description.........................................................................................................................6
2.5.2 Screenshots................................................................................................................................6
2.6 Programming Assignment 6: Working with an array......................................................................7
2.6.1 Case description.........................................................................................................................7
2.6.2 Screenshots................................................................................................................................7
3 Quiz answers...........................................................................................................................................8
Page | 2
Fontys ICT - English Stream: Software - Introduction Visual Studio and C#
1 Quiz
Answers to the quiz-questions can be found in the last chapter.
1.1 Question 1
Can you find 3 errors in the piece of code below (line numbers do not belong to the code, but are added
to easily identify the lines with errors):
1 int myShoesize;
2 myShoesize = 44.5;
3 double myShoesize;
4 myShoesize = 39.5;
5 int double;
6 double = 44;
1.2 Question 2
Consider the following piece of code:
List<int> numbers = new List<int>();
numbers.Add(7);
numbers.Add(4);
numbers.Add(25);
numbers.Insert(1, 99);
Mention, in correct order, the numbers stored in the List<int> after performing this piece of code.
1.3 Question 3
What are the values of the variables div, remainder, x and y after running this piece of code:
int a = 97;
int b = 20;
int div = a / b;
int remainder = a % b;
int x = ((a / b) / b) / b;
int y = ((a % b) % b) % b;
1.4 Question 4
What is the value of variable result after running this piece of code:
int myCapital;
myCapital = 45-10;
int myBanksCapital;
myBanksCapital = 9646104;
string result;
if ( myCapital + myBanksCapital > 1000000 )
{
result = "Together we are rich!";
}
else
{
result = "Poor us ! ! !";
}
Page | 3
Fontys ICT - English Stream: Software - Introduction Visual Studio and C#
1.5 Question 5
What is the value of the variable sum after running this piece of code:
int sum = 0;
1.6 Question 6
What is the value of the variable sum after running this piece of code:
int a = 0 ;
int sum = 0;
int blip = 10;
while ( a < 7 )
{
if (a % 2 == 0)
{
sum = sum + blip;
}
else
{
sum = sum + a;
}
a = a + 1;
}
1.7 Question 7
What is the value of variable sum after running this piece of code:
Page | 4
Fontys ICT - English Stream: Software - Introduction Visual Studio and C#
Page | 5
Fontys ICT - English Stream: Software - Introduction Visual Studio and C#
Make use of these inputted values to show a multiplication table; can you make use of a for-
statement to do this?
For example, when the base number is 5 and amount of multiplication is 9, the output would be:
1x5=5
2 x 5 = 10
3 x 5 = 15
4 x 5 = 20
5 x 5 = 25
6 x 5 = 30
7 x 5 = 35
8 x 5 = 40
9 x 5 = 45
2.5.2 Screenshots
Page | 6
Fontys ICT - English Stream: Software - Introduction Visual Studio and C#
Difficulty:
The assignment covers the following learning goals:
First ask the user for how many persons (e.g. 3 persons)
Then ask for the name and age for each of the persons (e.g. 3 times)
Finally, show the inputted data where each person is on a new line
2.6.2 Screenshots
Page | 7
Fontys ICT - English Stream: Software - Introduction Visual Studio and C#
3 Quiz answers
Question Answer
1 Line 2 (not possible to assign that value to an int-variable)
Line 3 (there is already a variable with that name)
Line 5 (double is a reserved word, cannot be used as identifier for a variable)
2 7, 99, 4 , 25
3 div = 4, remainder = 17, x = 0, y = 17
4 "Together we are rich!"
5 sum = 30
6 49 ( = 10 + 1 + 10 + 3 + 10 + 5 + 10 )
7 "725"
Page | 8