Jump to content

Frank

Members
  • Posts

    12
  • Joined

  • Last visited

About Frank

  • Birthday 07/28/2000

Profile Information

  • Gender
    Male
  • Location
    Argentina

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Frank's Achievements

  1. Object-oriented programming is based on scheduling classes; unlike the structured programming, which is centered on the functions. A class is a mold that then create multiple objects with similar characteristics. A class is a template (mold), which defines attributes (variables) and methods (functions) The class defines the attributes and methods common to all objects of that type, but then every object will have its own values and share the same functions. We must create a class before you can create objects (instances) of that class. When you create an object of a class, it is said that an instance of the class or object itself is created. The structure of a class is: Problem 1: Make a class load that allows the name and age of a person. Show the data loaded. Print a message if you are elderly (age >= 18) Program: The name of the class must refer to the concept (in this case we named Person): class Person The attributes define them within the class but outside the main: private string nombre; private int edad; We shall see that an attribute is normally defined with the private clause (this does not allow access to the attribute from other classes) Those attributes are accessed from any function or class method (except main) After defining the attributes of the class we must declare methods or functions of the class. The syntax is similar to the main (without the static clause): In the INIT method (which is the first thing we call in the main) keyboard loaded attributes name and age. As we can see the initialize method may make access to two attributes of the Person class. The second method aims to print the contents of the attributes name and age (data attributes previously loaded to run the initialize method): The third method is intended to display a message if the person is adult or not: Finally in the main declare an object of the Person class and call methods in a proper order: Person per1 = new Person(); //Declaration and object creation per1.Init(); //Calling a method Problem 2: Develop a program that loads the sides of a triangle and implement the following methods: initialize the attributes, print the value of the long side and another method that shows whether or not equilateral. Program: This problem requires three attributes define where we store integer values of the sides of the triangle: The first method to be called from the main Initialize is where we load the three key attributes: The BiggerSide method shows the highest value of the three integers admitted: As we can see when a problem becomes more complex and it is easier to separate the different algorithms ordered in various methods and not encode everything in the main. The final method in this class checks whether the three admitted integers are equal: In the main we create an object of the Triangle class and call the respective methods:
  2. Any problem that requires a repetitive structure can be solved using the while statement. But there is another repetitive structure whose pose is easier in certain situations. In general, the structure used for situations in which we know how many times we want the statement block is run. Example: charge 10 numbers, enter 5 marks of students, etc. We know in advance the number of times we want the block repeated. We will see, however, that in the C# language structure can be used for any repetitive situation, because ultimately it is nothing but a structure while widespread. Graphic representation: In its most typical and basic form, this structure requires an integer variable that serves as a lap timer. In the section indicated as "counter initialization" is usually placed the name of the variable that will counter by assigning to that variable an initial value. In the section "condition" the condition that must be true for the cycle to continue (if false, the cycle will stop) is placed. And finally, in the section of "counter increase" an instruction to change the value of the variable that counter (once to allow the condition is false) is placed When the cycle begins, before giving the first round for the variable takes the value indicated in the section of "counter initialization." Verified immediately, automatically, if the condition is true. If so block cycle operations is executed, and when the same instruction has been placed in the third section is executed. Then he turns to control the value of the condition, and so it goes until the condition deliver a fake. If we know how many times to repeat the block is very simple to use a for, for example if we want to repeat 50 times the block of statements can be made as follows: The FOR's variable can have any name. In this example, the defined named f. Consider the example: The f variable can be modified within the block for operations, although this could cause problems if the programmer logic is inexperienced. The f variable can be initialized to any value and end at any value. Moreover, it is not mandatory that the modification statement is an increase of counter type (f++). Any instruction that changes the value of the variable is valid. If for example f = f + 2 is written instead of f++, the value of f will be increased by 2 at every turn, not to 1. In this case, it means that the cycle does not carry out the 50 laps but only 25. Problem 1: Make a program that prints screen numbers 1 to 100. Flowchart: We can observe and compare with the problem made the while. With the structure while COUNTER x used to count laps. With COUNTER for f fulfills that function. Initially as f is 1 and does not exceed the block 100 is executed, f print content at the end of the variable f repeating block is incremented by 1, and 2 is not more than the instruction block 100 is repeated. When the variable reaches for 101 out of the repetitive structure and continues the execution of the algorithm shown after circle. The f variable (or whatever you decide to call it) must be defined as a variable. Program: Problem 2: Develop a program to load 10 values by keyboard and then we show the sum of the input values and their average. This problem already developed, we will resolve using the FOR structure. Flowchart: In this case, the FOR's variable (f) only the required for the statement block is repeated 10 times. Program: The problem requires 10 values, Consider braces to enclose statement block for repeated within. The average is calculated outside for after loading the 10 values.
  3. I've just subscribed to your channel
  4. Frank

    Favorite RPG?

    Final Fantasy 7!!!
  5. A repetitive structure allows to execute an instruction or set of instructions several times. A repetitive execution of judgments is characterized by: - The judgments or recurring. - The test or condition before each iteration, will motivate that are not repeated or judgments. While repeating structure. Graphical representation of the structure while: We must not confuse the graphical representation of the repetitive structure WHILE with conditional structure IF Operation: First the condition is verified, if it is true that the operations indicated by the branch of True run. A true branch plotted in the bottom of the condition. A line at the end of the repeat block connected to the top of the repetitive structure. If the condition is False continues False branch and leaves the repetitive structure to continue the execution of the algorithm. The block is repeated while the condition is true. Important: If the condition always returns true we are in the presence of an infinite repeating cycle. This situation is a programming error, the program never ends. Problem 1: Make a program that prints screen numbers 1 to 100. Without knowing the repetitive structures we can solve the problem by using a sequential structure. Initialize a variable with the value 1, then print the variable, the variable we increase again and so on. Flowchart: If we continue with the diagram we would not reach the next 5 pages to finalize it. Use a sequential structure to solve this problem it causes a flowchart and a program in C # too long. Now Look for the repetitive structure while using a solution: It is very important to analyze this diagram: The first operation initializes the variable x to 1, then starts while the repetitive structure and have the following condition (x <= 100), while the variable x is less than or equal to 100. When running condition returns TRUE because the content of x (1) is less than or equal to 100. When the true condition instruction block containing the while statement is executed. The statement block contains an output and an operation. The content of x is printed, and then increments the variable x by one. The operation x = x + 1 is read as "in the variable x the content of x plus 1 is saved." That is, if x contains one executed after this operation is stored in xa 2. At the end of the block of instructions containing the repeating structure is again checked the condition of the repetitive structure and the process explained above is repeated. While the condition returns true the statement block is executed; to return false verification of the condition leaves the continuous repetitive structure and algorithm, in this case the program ends. The hardest part is the definition of the condition of the while block structure and what instructions will be repeated. Note that if, for example, have the condition x> = 100 (if x is greater than or equal to 100) causes no syntax error but we are in the presence of a logic error because at first assessed the condition returns false and not executes the block of statements we wanted to repeat 100 times. There is no recipe to define a condition of a repetitive structure, but is achieved with continuous practice solving problems. Once you raised the diagram must verify if it is a valid solution to the problem (in this case should print the numbers 1 to 100 on the screen), for it can keep track of the flow diagram and the values ​​taken by the variables along the execution: Important: We can see that the repetitive block if the condition returns false the first time can not be executed any time. The variable x must be initialized with some value before the operation x = x + 1 is executed in the event of not being initialized a compilation error occurs. Program: Recall that a problem will not be 100% solved if we do the program in C # that shows the desired results. Let's try some modifications of the program and see what changes should be made to: 1 - Print numbers from 1 to 500. 2 - Print numbers from 50 to 100. 3 - Print numbers of -50 to 0. 4 - Print numbers from 2 to 100 but 2 by 2 (2,4,6,8 .... 100). Replies: 1 - We must change the condition of the while with x <= 500. 2 - We need to initialize x with the value 50. 3 - Initialize x to the value -50 and set the condition x <= 0. 4 - Initialize x with value 2 and within the x enhance repeating block 2 (x = x + 2) Problem 2: Write a program that prompts the burden of a positive value and show us from 1 to the value entered one by one. Example: If we enter 30 to display on screen the numbers from 1 to 30. It is of fundamental importance to analyze the flowcharts and subsequent coding in C # of the following problems in several other unseen problems in the previous year situations arise. Flowchart: We can see that is entered by keyboard the n variable. The operator can load any value. If the operator load 10 repetitive block is executed 10 times, as the condition it is "While x <= n", ie "while x is less than or equal to 10"; x begins because one and is incremented by one each time the block is executed repetitive. A test chart we can make giving values to variables; for example, if we enter track 5 it is: n x 5 1 (It prints x) 2 " " 3 " " 4 " " 5 " " 6 (Exits while because 6 is not less than or equal to 5) Program: The names of the variables and x can be words or letters (as in this case) The variable x is called the counter. An accountant is a special type of variable that increases or decreases with constant values during execution of the program. X indicates the counter at all times the amount of printed values on the screen.
  6. Eclipse is a professional IDE, which at first may seem complex development of our first programs. All Eclipse program requires the creation of a "project", for this we must select from the menu of options: Or from the toolbar of the Eclipse: Now, the dialogue where we define our project name appears: In the text field "Project Name" we enter as name: Project1 and leave all other options dialogue with the defaults. Click the "Finish" button. Now in the window "Package" the project we've just created appears: As a second step we will see that every Java program requires at least one class. To create a class we select from the menu of options: Or from the toolbar of the Eclipse: In the dialog that appears we must define the class name (in our first example we will call the class as Class1, then see that it is important to define a name that represents the goal of it), the other data of the dialogue we left with the default values: After pressing the "Finish" button we have the file where we can code our first program: Later we will see the files created in a project, now devote ourselves to encode our first program. In the editing window already we have the skeleton of a Java class that the Eclipse environment we created automatically. All Java program should define the main function. This function must encode in the class, "Class1". We proceed to type the following: That is we have encoded in the Eclipse IDE our first program: As a last step we have to compile and run the program, this can be done from the menu of options: Or from the toolbar of the Eclipse: Unless there are coding errors, we'll see the result of running in a window of Eclipse called "Console" that appears at the bottom:
×
×
  • Create New...