Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Introduction

Console applications are the remnants of the old operating systems, for servers and personal
computers, which served as a means of communication between the computer and the user.
Today console applications are still mainly used in background applications, batch process files,
system settings etc.
So, in a didactic way, console applications are the best way to start learning a programming
language.
Before starting to program the first program in visual c# it is necessary to know the programming
environment:

Given the salary of a worker, it is required to calculate the new salary that he/she will have after
an increase, considering the following characteristics:
a) If the original salary is greater than or equal to 10,000, the increase will be 10%
b) If the original salary is less than 10,000, the increase will be 12%
The new salary is required to be printed at the end of the calculation.
What will be the input data to be entered by the user?

Select one:
New salary
The original salary (based on this data the process will be carried out and is the process
variable).
Employee's name
Percent increase
Your answer is correct.

Question 2
Select the option that would represent a way in which we can express with pseudocode the
allocation of the percentage increase to the salary
Select one:
SalaryIncrease = OriginalSalary * PercentageIncrease
sueldoNuevo = OriginalSalary + PercentageIncrease

IF newSalary IS GREATER THAN OR EQUALS 10000 THEN


PRINT newSalary
IF newSalary IS LESS THAN 10000 THEN
PRINT originalSalary

IF ORIGINAL SALARY IS GREATER THAN OR EQUALS 10000 THEN


PercentageIncrease = 10%
IF ORIGINAL SALARY IS LESS THAN 10000 THEN
PercentageIncrease = 12%.

This is a pseudocode form of representing the assignment


IF originalSalary IS GREATER THAN OR EQUALS 15000 THEN
PercentageIncrease = 7%
IF originalSalary IS LESS THAN 15000 THEN
PercentageIncrease = 5%
Your answer is correct.

Question 3
Of the following options, what would be the flowchart representation of the decision of what
percentage increase to apply according to the variable salaryOriginal?

Question 4
According to the problem statement and analysis, what is the expected output?

Select one:
The percentage increase
New salary

According to the approach, this is the output variable


The original salary

The increase over the previous salary

Your answer is correct.


Principle of the form
Introduction P2
In the design of basic solutions, using the C programming language, it is very important to know
the arithmetic operators to perform calculations, the relational operators to be able to make
decisions and the character print statements to request data and display the results obtained.
Arithmetic operators
They are used to perform basic calculations with the data you have. The basic operators in most of
today's programming languages are:

Here are some examples of basic operations:


A = 8 + 6; //The result will be 14 and is stored in the variable A
B = A - 3; //B will take the value of 11, which is the result of subtraction
C = B / 2; //C will take the result of division 5.5
D = B % 4; //The value of D will be 3, since 11 divided by 4 is equal to 2 integers and there are 3 left
over
//The operation modulo (%) calculates whatThe module operation (%) calculates the remainder of
the division

Relational operators
They are used to make comparisons between values and to be able to take a path if the
comparison is true, or another path if it is false. The relational operators are:

Considering the values calculated for A, B, C and D, above, the following relational expressions
would give these results:
A < B The result of the expression would be false, because 14 is not less than 11
B > C It would be true because 11 is greater than 5.5
D <= C It is true because 3 is less than 5.5 (Although it is not equal, and if it were equal
it would also be true, although it is not less).
A >= B + D It is true because 14 (Value of A) is equal to 14 (Sum of B and D), although
is not greater.
A == 5 * D It would be false because 14 is not equal to 15.
D != C Is true because 3 is different from 5.5
As you could observe, the operator <= evaluates if the values involved are equal or if the first one
is less than the second one, and with any of these two comparisons that is true, the value of the
expression will be true; the same happens with >=.
This type of expression is used with the if conditional, which evaluates the expression provided,
and if it is true, the block of instructions following the if statement is executed, but if the
expression is false, the block following the else statement, if any, is executed.
Returning to the values of variables A, B, C and D, we show you these examples of if:

if(A>B)
{ Console.WriteLine("A is greater than B"); //This block is executed because 14 is
Console.WriteLine("Starting true case process"); // greater than 11
}
else
{ Console.WriteLine("A is not greater than B"); //In this case, this block is not executed
Console.WriteLine("Starting false case process");
}

if(B % 2 == 0)
{ Console.WriteLine("B is an even number"); //This block is not executed because what
Console.WriteLine("Starting true case process"); // left over from dividing 11
} // by 2 is 1 (11 / 2 equals 5 and 1 is left over), and 1 does not equal 0
else
{ Console.WriteLine("B is an odd number "); //This block is executed because the
Console.WriteLine("Starting false case process"); //expression is false
}

Escape sequences
They are a pair of special characters that allow to give a special format to the output of
information in the console.
Whenever you use these escape sequences, be sure to use the inverted diagonal and not the
normal one /.
Example of the use of escape sequences:
Console.Write("Example of the use of escape sequences");
Console.Write("Encryption");
Console.Write("Remember to use "and not /");
Console.Write("My name is "Escape sequence");

The console output of this code would be as follows:


The first line is printed in the console and the cursor is moved back to the beginning of the line,
staying just below the letter E of the word Example, so the word Encimado overwrites the word
Example and the space that follows it; then there is a line break that causes the 10 asterisks to be
printed in the next line without overwriting anything; in the next line we see how the diagonal is
inverted, and in the last one we do a tab advance (8 spaces).Then there is a line break that causes
the 10 asterisks to be printed on the next line without overwriting anything; on the next line we
see how the inverted diagonal is displayed, and on the last line we make a tab advance (8 spaces)
before displaying the name in quotation marks.
We need to develop a program in C# that requests an integer X from the user; if this number is
even, a triangle formed by asterisks will be displayed on the console; but if the value is odd, a
rectangle will be displayed; finally, after printing the figure, a message will be displayed to indicate
whether the number is positive, negative or null.
Based on the above, what will be the sentence to determine if the value of X is an even number?

Select one:
if (X/2 >=1)

if (X/2 != 0)

if (X%2 > 0)

if (X%2 == 0) (Correct, if the remainder of the division by 2 is 0, the number is even)


Your answer is correct.

Question 2
To display the triangle formed by asterisks on the console, what is the correct instruction?
Select one:
Console.WriteLine(“****\t***\t**\t*”);

Console.Write(“*/r**/r***/r****”);

Console.Write(“*\n**\n***\n****”);

Console.WriteLine("*/n**/n**/n***/n****");
Your answer is correct.

Question 3
Which instruction will let us know if the number X is positive?

Select one:
if (X > 0) (Correct, numbers greater than 0 are positive)
if (X < 0)
if (X == 0)
if (X = 0)
Your answer is correct.

Question 4
What is the operation that obtains what is left over when performing a division?

Select one:
Rounding
Modulo (Correct, that's the name of the operation that obtains the residue)
Adjustment
Percentage
Your answer is correct.

Question 5
To find out if the number X is null, what would be the correct sentence?

Select one:
if (X = 0) (Incorrect, performs an assignment and not a comparison)
if (X == 0)
if (X%2 == 0)
if (X%2 != 0)
Your answer is incorrect.
Introduction P3
In general, the instructions in an application are executed one after the other, in the order in
which they were written. This process is known as sequential execution. Several C# statements
allow you to specify that the next statement to execute is not necessarily the next in the sequence.
This is known as transfer of control. One of the most commonly used transfer of control
instructions is the if statement, which performs an action if a condition is true, or ignores the
action if the condition is false. The if ... else statement performs an action if a condition is true or
performs a different action if the condition is false. The switch instruction performs one of several
different actions, depending on the value of an expression.

The if statement is called a simple selection statement because it selects or ignores a single action
(or, as we will soon see, a single group of actions). To the instruction if ... else is called a double
selection instruction because it selects one of two different actions (or group of actions). The
switch instruction is called a multiple selection instruction because it selects one of several
different actions (or groups of actions).

Conditional operator (?:)


C# has a conditional operator (?:) that can be used instead of an if ... else statement. This is the
only ternary operator in C#; that is, it uses three operands. Together, the operands and the
symbols ¿: form a conditional expression. The first operand (to the left of the ?) is a Boolean
expression; that is, an expression that evaluates to a Boolean type value: true or false. The second
operand (between ? and the :) is the value of the conditional expression if the boolean expression
is true and the third operand (to the right of the :) is the value of the conditional expression if the
boolean expression is false. For example, the instruction:
Console.WriteLine (Calif >= 60 ? "enough" : "not enough");
Prints "sufficient" if the boolean expression calif >=60 is true and "not sufficient" if it is false.

What does the following statement print when the calif value is equal to 60?
Console.WriteLine(calif >=60 ? "Passed" : "Failed" );

Select one:
Nothing
Failed
Error
Approved (It is correct because of the definition of the ? operator, based on the book "How to
program in C#", by Deitel and Deitel, page 120).
Your answer is correct.

Question 2
The ?: operator performs essentially the same function as the if ... else statement. Sometimes,
the ?: operator is used when the if statement .... else cannot be occupied.
Consider the C# statement analyzed in the parent problem (first question) What does the
following statement print when the calif value is less than 60?
Select one:
Nothing
Error
Failed (It is correct because of the definition of the ? operator, based on the book "How to
program in C#", by Deitel and Deitel, page 120).
Approved
Your answer is correct.

Question 3
Completed
Recall that the operator ?: evaluates a condition and based on that it decides which option to take.
The first operand (to the left of the ?) is a Boolean expression; that is, an expression that evaluates
to a Boolean type value: true or false. The second operand (between ? and the :) is the value of
the conditional expression if the Boolean expression is true and the third operand (to the right of
the :) is the value of the conditional expression if the Boolean expression is false
Consider the C# statement analyzed in the parent problem (first question) What does the
following statement print when the value of calif is 80?

Select one:
Failed
Error
Nothing
Passed (Correct by operator definition, based on the book "How to program in C#", by Deitel
and Deitel, page 120).
Your answer is correct.

Instruction P4
Read the following problem, generate a solution applying the concepts of structured programming
and the topics related to control structures.
A quick consultation company wants to obtain the average results of a satisfaction survey for a
given product in a shopping mall.
The possible responses for evaluating a product are 1) Excellent 2) Good 3) Poor
The company requires software that captures the results of this exit survey from an undetermined
number of people and, upon deciding to close the survey, displays on screen the response
averages of the three options indicated.
The number of respondents and the percentage of each of the options should be indicated on the
screen.

Based on the above, which program control statement is the most appropriate to capture the
response of an undetermined number of people to be surveyed?
Select one:
For - IF
If
For
While(Correct, because in an infinite structure controlled by an output condition, in this case
if you want to capture a new record)
Your answer is correct.

Question 2
What is the means by which the program flow determines that it should terminate and display the
final results?

Select one:
By modifying the while condition
Determining the number of cycles
Indicating the final results after each answer
With a condition that closes the key of the cycle (Incorrect, because it would be a language
syntax error).
Your answer is incorrect.

Question 3
What is the most optimal way to determine the number of respondents to the survey?

Select one:
Asking the number of respondents at the end of the program
By incrementing a counter variable (Correct, because by incrementing by one as many times
as the contents of the while cycle are executed, the number of persons is determined).
By means of a timer
Incrementing by one the variables of each answer
Your answer is correct.

Question 4
Data type of variables to store the averages of each option?

Select one:
Int (Incorrect, only whole parts of the result of the operation will be considered)
Char
Float
String
Your answer is incorrect.

Question 5
Ideal structure for comparing possible user responses?

Select one:
Two sequential If (Incorrect, since only two of the three options could be compared)
For
Switch
If-else
Your answer is incorrect.

Introduction P5
to Arrangements
One of the most common problems in various information systems is the treatment or processing
of a large volume of data or information.
The variables used so far are properly called scalar variables, because they can only store or
process one data at a time.
For example if you want to store name and age of 15 people with the traditional method you will
need 30 variables and it is only name and age of 15 people, add more data and more people and it
is time to start analyzing other types of variables.
Variables that are capable of storing and manipulating data sets at the same time are used.
Variables of type array if they allow to store and process data sets of the same type at the same
time.
Each data within the array is known as an array element and is symbolized and processed (capture,
operation, display) using the respective array name and a subscript indicating the relative position
of the element with respect to the other elements of the array, just remember that in C# the first
position, element or row is 0 (zero), ex.
NAMES
Juan →nombres(0)
Pedro → nombres(1)
Rosa → nombres(2)
Jose → nombres(3)
In C# however their problems are similar to those of normal variables i.e. you have to declare
them, capture them, do operations with them, display them, compare them, etc.
Let's see the following example of C# array handling
In the previous program the type of arrangement handled is:

Select one:
Two-dimensional arrays
One-dimensional arrays (That's right, you are working with a one-dimensional array).
Three-dimensional arrangements
Chain arrangement
Your answer is correct.

Question 2
Based on the following statement, how many elements does the array have?
int[] number = new int[5];

Select one:
6
5 (Correct, a five-element array is defined)
The statement is poorly defined
4
Your answer is correct.

Question 3
What function does the following code fragment perform?
for (i=0; i<=4; i
{
Console.Write("Enter data number {0}: ", i+1);
number[i] = Convert.ToInt32(Console.ReadLine());
}

Select one:
Filling of the array (Correct. The values for the declared array are entered.)
Sum of array elements
Impression of the arrangement
Array storage
Your answer is correct.

Question 4
If the following values are entered in the program 1, 2, 3, 4, 5
What is printed at the output?

Select one:
0
120
1, 2, 3, 4, 5
15 (Correct, it is the sum of the elements entered)
Your answer is correct.

Question 5
What is the variable with which the index is controlled within the program?

Select one:
number
i (Correct, this variable is used to manage the array)
new
sum

Your answer is correct.

You might also like