Fiche de révision : Dairy Purchase Data Processing Course

📋 Course Outline

  1. Variable declaration and initialization
  2. Arrays vectors and matrices in PSeInt
  3. While loop with string condition
  4. Maximum limit control for array bounds
  5. Team data input and indexing
  6. For and repeat loops for price validation
  7. Minimum price search algorithm
  8. Nested loops for final purchase report
  9. Overall algorithm flow for dairy purchases

📖 1. Variable declaration and initialization

🔑 Key Concepts & Definitions

  • Variable declaration : A variable declaration tells PSeInt the data type and reserves memory before any use.
  • Initialization : Initialization assigns a known starting value so the program does not work with random garbage.
  • Constant MAX : A named constant stores a fixed numeric limit used to size arrays and control bounds.
  • resp as string : resp is a string variable that stores the user’s yes/no answer for loop control.
  • minP as real : minP is a real variable used to temporarily hold the current minimum price while scanning providers.

📝 Essential Points

  • Using a variable before declaring it triggers an error in PSeInt.
  • Declaration reserves memory but does not guarantee a meaningful value until initialization.
  • MAX is set to 100 to define the maximum number of teams the arrays can store.
  • n starts at 0 because no team has been entered yet.
  • resp is initialized to "si" so the main While loop starts immediately.
  • minP is real because prices can include decimals (USD).

💡 Memory Hook

Declaration first, then initialization: “declare to reserve, initialize to avoid garbage”.

📖 2. Arrays vectors and matrices in PSeInt

🔑 Key Concepts & Definitions

  • Vector names[MAX] : A vector is a 1D array that stores one value per index, here team names.
  • Matrix precios[MAX, 5] : A matrix is a 2D array that stores values by two indices, here prices by team and provider.
  • Vector menor[MAX] : A vector stores one computed result per team, here the minimum price per team.
  • Named constant MAX : MAX is used instead of a literal number to make array sizing and logic adjustable in one place.
  • Indexing with integers : Array indices in this program are integers used to access stored elements.

📝 Essential Points

  • names[MAX] is declared as a 1D vector with positions from 1 up to MAX.
  • precios[MAX, 5] is declared as a 2D matrix where rows represent teams and columns represent providers.
  • menor[MAX] stores the final minimum price for each team at the same team index i.
  • Using MAX lets you change the capacity by editing MAX once (e.g., from 100 to 200) without rewriting logic.
  • The meaning of indices is fixed: prices[i, j] uses i for team and j for provider.
  • Attempting to access beyond the allocated size leads to runtime errors, so bounds control is required.

💡 Memory Hook

1D = one index (names, menor); 2D = two indices (precios: team × provider).

📖 3. While loop with string condition

🔑 Key Concepts & Definitions

  • While loop : A While loop repeats a block while its condition is true, checking the condition before executing the body.
  • Pre-test condition : A pre-test condition is evaluated before the loop body, so the body may run zero times.
  • Minusculas() : Minusculas() converts a string to lowercase to make comparisons case-insensitive.
  • String comparison sensitivity : String comparisons treat different capitalization as different values unless normalized.
  • resp loop control : resp is the variable whose value determines whether the While loop continues.

📝 Essential Points

  • The loop condition is Minusculas(resp) = "si".
  • Because it is pre-test, if the condition is false at the start, the loop body never runs.
  • Minusculas() allows inputs like "SI", "Si", "sI", and "si" to be treated the same.
  • Without Minusculas(), "SI" would not equal "si" in string comparisons.
  • resp must be updated after each team entry to reflect the user’s new decision.
  • If resp were not initialized, the first evaluation could be unpredictable and the loop might not start correctly.

💡 Memory Hook

While is “check first”: normalize resp with Minusculas() so “SI” equals “si”.

📖 4. Maximum limit control for array bounds

🔑 Key Concepts & Definitions

  • Overlow protection : Overflow protection prevents writing past the fixed-size capacity of arrays.
  • Bound check with n = MAX : A bound check compares the current count n with MAX to detect when the arrays are full.
  • Controlled loop exit : A controlled exit changes the loop condition variable so the loop stops safely.
  • resp forced to "no" : Setting resp to "no" forces the While condition to become false on the next evaluation.
  • Array size fixed : In PSeInt, arrays have a fixed size determined at declaration time.

📝 Essential Points

  • Inside the While loop, the first step is to verify whether n has reached MAX.
  • The check is If n = MAX Entonces ... FinSi.
  • When n = MAX, the program writes a message indicating the maximum limit was reached.
  • Then it sets resp <- "no" to ensure the While loop ends in a controlled way.
  • Without this block, entering team number MAX+1 could cause an out-of-range access error.
  • The purpose is to preserve data integrity and avoid runtime failure.

💡 Memory Hook

When n hits MAX: stop writing by flipping resp to "no".

📖 5. Team data input and indexing

🔑 Key Concepts & Definitions

  • Team counter n : n counts how many teams have been entered so far and drives where data is stored.
  • Increment before storing : Incrementing n before saving ensures the first stored team uses a valid array index.
  • Array index starts at 1 : In this program’s arrays, valid indices begin at 1, not 0.
  • names[n] assignment : names[n] stores the entered team name at the current team index.
  • Sin Saltar output : Sin Saltar prints a prompt without moving to a new line so input appears on the same line.

📝 Essential Points

  • The program increments n with n <- n + 1 before assigning names[n].
  • This avoids using names[0], which is not a valid index in PSeInt for these arrays.
  • The first team is stored at names[1], the second at names[2], and so on.
  • The prompt prints "Equipo #" followed by n to label the entry number.
  • The input is read with Leer nombres[n] after showing "Nombre del equipo:".
  • Sin Saltar is used to keep the prompt and the user’s typed name on the same console line.

💡 Memory Hook

Index rule: increment first so the first team lands on index 1.

📖 6. For and repeat loops for price validation

🔑 Key Concepts & Definitions

  • For j <- 1 Hasta 5 : A For loop iterates a known fixed number of times, here exactly 5 providers.
  • Repetir...Hasta Que : A repeat-until loop executes the body at least once and repeats until the condition becomes true.
  • Post-test validation : In Repetir...Hasta Que, the condition is checked after reading input, so invalid values trigger another read.
  • Price validation condition : The validation requires each entered price to be strictly greater than 0.
  • Nested loops for input : Nested loops combine provider iteration with repeated prompting until each price is valid.

📝 Essential Points

  • The For loop sets j from 1 to 5 to ensure exactly five provider prices are collected.
  • Inside it, Repetir...Hasta Que ensures the user enters a price at least once before validation.
  • The read is Leer precios[n, j] for the current team n and provider j.
  • If precios[n, j] <= 0, the program prints an error message.
  • The loop exits only when precios[n, j] > 0.
  • The choice is deliberate: For handles fixed count (5), while Repetir handles user re-entry until valid.

💡 Memory Hook

For = fixed 5; Repetir = keep asking until price > 0.

📖 7. Minimum price search algorithm

🔑 Key Concepts & Definitions

  • Minimum search : Minimum search scans a set of values and keeps the smallest seen so far.
  • Provisional minimum minP : minP stores the current smallest price during the scan across providers.
  • Initialize minP with first provider : The algorithm starts by assuming the first provider’s price is the minimum candidate.
  • Update rule prices[n, j] < minP : When a new price is smaller than minP, minP is replaced by that price.
  • Store result menor[n] : After scanning all providers, the final minimum is saved in menor for that team.

📝 Essential Points

  • minP is initialized as precios[n, 1] before the comparison loop.
  • The comparison loop runs j from 2 to 5 to avoid comparing the first value with itself.
  • The update condition is If precios[n, j] < minP Entonces minP <- precios[n, j].
  • After the loop, the result is stored with menor[n] <- minP.
  • The algorithm uses exactly one pass over the 5 provider prices per team.
  • The final minimum can include decimals because minP and menor are real.

💡 Memory Hook

Start with provider 1 as “champion”; replace champion only when you find a smaller price.

📖 8. Nested loops for final purchase report

🔑 Key Concepts & Definitions

  • Report generation : Report generation prints a formatted summary after all inputs and computations finish.
  • Outer loop over teams i : The outer loop iterates through the entered teams to print each row of the report.
  • Inner loop over providers j : The inner loop iterates through the 5 providers to print each price column.
  • Table header string : The header line labels the columns for equipment and provider prices plus the minimum.
  • Sin Saltar for row formatting : Sin Saltar keeps multiple cells on the same line to form a table row.

📝 Essential Points

  • If n = 0, the program prints "No se ingresaron equipos." instead of a table.
  • Otherwise it prints a header: Equipo | Prov1 | Prov2 | Prov3 | Prov4 | Prov5 | Menor.
  • The outer loop is Para i <- 1 Hasta n Hacer to print one row per team.
  • The inner loop is Para j <- 1 Hasta 5 Hacer to print five prices per row.
  • Each price is printed with Sin Saltar so the row stays on one line.
  • After the inner loop, menor[i] is printed and the program ends the row with a line break.

💡 Memory Hook

Two loops = table: i makes rows, j makes columns; Sin Saltar keeps each row aligned.

📖 9. Overall algorithm flow for dairy purchases

🔑 Key Concepts & Definitions

  • Main While input loop : The main While loop controls whether the program keeps accepting new teams based on resp.
  • Fixed provider count : The algorithm assumes exactly 5 providers, so provider loops always run from 1 to 5.
  • Conditional blocks : Conditionals handle decisions like maximum limit, invalid prices, and empty report cases.
  • Vectors and matrices roles : The algorithm uses vectors for names and minimums and a matrix for all prices.
  • Three loop layers : The full flow combines While (teams), For/Repetir (prices), and nested For (report).

📝 Essential Points

  • The flow starts with declarations, then initialization, then enters the While loop controlled by resp.
  • Within the While loop, the program checks the maximum capacity using n = MAX before accepting another team.
  • For each team, it increments n, reads the team name, then collects 5 validated provider prices.
  • After reading prices, it computes the minimum using minP and stores it in menor[n].
  • After each team, it asks "¿Hay más equipos? (si/no):" and updates resp for the next While evaluation.
  • Finally, it prints either an empty-message when n = 0 or a full table using nested loops over i and j.

💡 Memory Hook

While teams → validate 5 prices → compute min → ask continue → print table.

📊 Synthesis Tables

While vs Repetir for user input

StructureCondition checkRuns at least once
WhileBefore the body (pre-test)No, if condition is false initially
Repetir...Hasta QueAfter the body (post-test)Yes, it executes once before checking

⚠️ Common Pitfalls & Confusions

  1. Forgetting to declare variables first causes an error in PSeInt.
  2. Not initializing resp can prevent the While loop from starting or make behavior unpredictable.
  3. Using n without the increment-before-store rule can lead to invalid index 0 access.
  4. Skipping the n = MAX bound check can trigger out-of-range array access.
  5. Using string comparison without Minusculas() can reject valid inputs like "SI".
  6. Starting the minimum scan at j = 1 can cause redundant comparison with the already-assumed minP value.

✅ Exam Checklist

  1. State why variables must be declared before use and what initialization prevents.
  2. Explain the difference between vector names[MAX] (1D) and matrix precios[MAX,5] (2D) in terms of indices.
  3. Write the While loop condition using Minusculas(resp) = "si" and describe why it is pre-test.
  4. Describe the maximum limit control when n = MAX and how resp <- "no" ends the loop safely.
  5. Explain why n is incremented before reading names[n] and how this avoids index 0.
  6. Describe how the For j <- 1 Hasta 5 and Repetir...Hasta Que work together to validate exactly 5 prices.
  7. State the exact validation rule for prices (must be > 0) and what happens when it fails.
  8. Reproduce the minimum search logic: minP starts at precios[n,1], loop j from 2 to 5, update when a smaller value is found, then store in menor[n].
  9. Explain how the final report uses nested loops: outer i from 1 to n and inner j from 1 to 5, plus the n = 0 empty-case.
  10. Summarize the full dairy purchases flow from initialization to final table output, including where each loop type is used.

Testez vos connaissances

Testez vos connaissances sur Dairy Purchase Data Processing Course avec 3 questions à choix multiples avec corrections détaillées.

1. What is the main purpose of declaring and initializing a variable before using it in PSeInt?

2. Why is it important to declare variables before using them in PSeInt, and what is the purpose of initializing variables after declaration?

Faire le QCM →

Révisez avec les flashcards

Mémorisez les concepts clés de Dairy Purchase Data Processing Course avec 9 flashcards interactives.

Variable declaration — purpose?

Reserves memory and defines data type.

Variable declaration in PSeInt

Declares data type, reserves memory

Arrays in PSeInt — role?

Store multiple values with indices for teams, providers, etc.

Voir les flashcards →

Cours similaires

Crée tes propres fiches de révision

Importe ton cours et l'IA génère fiches, QCM et flashcards en 30 secondes.

Générateur de fiches