Please enable JavaScript.
Coggle requires JavaScript to display documents.
20 QUESTION TEST (1) (What is programming? (Programming is the creative…
20 QUESTION TEST (1)
Programming is the creative process of writing code (instructions) written in a programming language (logical rules & syntax) to run on a computer.
- What are methods and properties?
A method is an action an object can perform
A property allows us to read or change the settings of the object.
-
-
- If you created a class to represent an address what might its properties be?
-
-
-
- What are the following made from, methods, properties, constructors, event handlers?
-
- Along with a suitable explanation, what is sequence?
Sequence is the normal order the computer processes lines of code. It processes one line after another. Comments are ignored and lines are not missed out until we break the rules of sequence.
public void JustAdd( )
{
Int32 a = 1; //first a is defined as type Int32 and initialised equal to 1
Int32 b = 2; //next line follows and b is defined as type Int32 and initialised to equal 2
Int32 total =0; //next total is defined as type Int32 and initialised to 0
total = a + b; //this line is next so total will become a + b, so total will be 3
}
- Along with a suitable example what is selection?
One way to break rules of sequence is through selection, by using an if else statement, to make a choice based on some condition being true or false.
public void CheckAge(Int32 Age)
{
if (Age < 21)
{
lblMessage.Text = "You are too young";
//this line will execute based on the if condition that the Age is less than 21 is true
}
else
{
lblMessage.Text = "Check OK"; //code will execute if the condition is false
}
}
- Along with a suitable example explain what is repetition?
Repitition is a way to break rules of sequence by using loops to repeat a section of code based on whether some condition is true or false.
Int32 Looper( )
{
Int32 Counter = 0;
Int32 Total = 0;
while(Counter < 3)
{
Total = Total +10;
Counter ++;
}
return Total;
}
At the start the value of Counter is 0, so condition Counter < 3 is true and the code in the while loop executes, Total will be incremented by 10 and then the condition checked again, each time the condition is Counter<3 is true the code in the while loop is run and Total incremented by 10. Because the Counter is also being incremented the loop will terminate when counter is equal to 3 (Counter<3 is false). The line outside the loop will execute and the value of total will be returned.
- Along with a suitable example what is proceduralisation?
- Proceduralisation is a long word used to describe making functions.
A simple function that accepts 2 numbers, adds them and returns the result:
Int32 NumbersAdd(Int32 Num1, Int32 Num2)
{
Int32 Result;
Result = Num1 + Num2;
return Result;
}
Parameters are named variables of a particular type used to pass data into functions/procedures. The values passed in are called arguments
- Along with a suitable example explain what is a function's return value?
- Return types enable a function to pass values (of a defined type) to other functions or variables by using the 'return' keyword.
[Consider example in question 12]
The numbers are added and the return type is Int32, so result is passed to a variable of the same type (as follows):
Int32 MyNumber = NumberAdd(1,2);
So here the result of 3 is returned by the Result variable and passed to myNumber by NumberAdd(1,2).
- Write a public function stub for the method Delete which accepts a single parameter representing the primary key of the record to delete (AddressNo). The function should have a Boolean return data type. The function should include a comment indicating where the code would go.
- //This function goes in the middle layer clsAddressCollection class
public Boolean Delete(Int32 AddressNo)
{
try
{
//create an instance of the data connection class called MyDatabase
clsDataConnection MyDatabase = new clsDataConnection();
//add the AddressNo parameter passed to this function to the
list of parameters to use in the database
MyDatabase.AddParameter("@ AddressNo", AddressNo);
//execute the stored procedure in the database
MyDatabase.Execute("sproc_tblAddress_Delete);
//set the return vaue for the fruntion
return true;
}
catch //do this if the code above fails
{
//report back that there was an error
return false;
}
}
- Write a section of code that creates an instance of an object called Address based on the class clsAddressCollection
-
- What is the difference between a getter and a setter?
- getter allows us to get a properties private member variable value
- setter allows us to set a properties private member variable value
- Along with a suitable example what is a variable?
A variable is a named section of memory of a particular data type used to store values of the same data type:
string Sentence="text";
This is a declaration of a variable of type string called sentence that is used to store the string value text
-
- Write suitable control IDs for the following:
- A text box for a first name
- A label to store errors
- A button to save data
- A list box displaying students
-