Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions experiment/posttest.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,40 @@
"d": "Incorrect. The presence of member functions in structures is not dependent on whether they are declared as pointers."
},
"difficulty": "intermediate"
},
{
"question": "10. Which statement about copying structures in C is correct?",
"answers": {
"a": "Only individual members can be copied one by one",
"b": "A structure variable can be assigned to another structure variable directly",
"c": "Structures cannot be assigned at all",
"d": "Structures can only be copied using pointers"
},
"correctAnswer": "b",
"explanations": {
"a": "Incorrect. Individual members can be copied, but direct assignment of the entire structure is also allowed.",
"b": "Correct. In C, one structure variable can be assigned to another of the same type directly.",
"c": "Incorrect. Structure assignment is allowed when both variables are of the same structure type.",
"d": "Incorrect. Pointers are not required for copying a structure variable."
},
"difficulty": "advanced"
},
{
"question": "11. Why are structures often preferred over arrays when storing student records?",
"answers": {
"a": "Because structures store only numeric values",
"b": "Because arrays can store multiple data types but structures cannot",
"c": "Because structures can group different data types such as name, roll number, and marks together",
"d": "Because structures automatically allocate dynamic memory"
},
"correctAnswer": "c",
"explanations": {
"a": "Incorrect. Structures can store many data types, not only numeric values.",
"b": "Incorrect. Arrays usually store elements of the same data type.",
"c": "Correct. Structures are ideal for grouping different but related data items into one record.",
"d": "Incorrect. Structures do not automatically allocate dynamic memory."
},
"difficulty": "advanced"
}
]
}
34 changes: 34 additions & 0 deletions experiment/pretest.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,40 @@
"d": "Incorrect. The function fun4 does not return 80 or 30 as output."
},
"difficulty": "intermediate"
},
{
"question": "10. Which statement best describes a structure in C?",
"answers": {
"a": "A structure can store only integers",
"b": "A structure groups related variables of different data types under one name",
"c": "A structure is used only for arrays",
"d": "A structure cannot be copied as a whole"
},
"correctAnswer": "b",
"explanations": {
"a": "Incorrect. A structure can contain members of different data types.",
"b": "Correct. A structure groups related variables of different data types under one name.",
"c": "Incorrect. Structures are not limited to arrays.",
"d": "Incorrect. A structure variable can be assigned to another structure variable as a whole."
},
"difficulty": "advanced"
},
{
"question": "11. Which of the following is a valid way to declare an array of structures?",
"answers": {
"a": "struct student s[10];",
"b": "struct student s(10);",
"c": "structure student s[10];",
"d": "struct student *s = 10;"
},
"correctAnswer": "a",
"explanations": {
"a": "Correct. This declares an array of 10 structure variables.",
"b": "Incorrect. Parentheses are not used for array declaration in C.",
"c": "Incorrect. C uses the keyword struct, not structure.",
"d": "Incorrect. This is not a valid declaration of an array of structures."
},
"difficulty": "advanced"
}
]
}
36 changes: 23 additions & 13 deletions experiment/procedure.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
### Working with Simulation

This simulation consists of four steps, with increasing complexity:

- Step 1. Define a Structure
- Step 2. Declare a Structure
- Step 3: Function to Fill a Structure
- Step 4: Use Structures to Handle Data

At each step,
* A set of instructions will be given in the top container.
* The corresponding code in C needs to be written, and then click on 'Check Solution'.
* The ideal solution will be shown in the right container next to your code.
* For going to the next step, click 'Yes' to Continue, or 'No' to stay at the same step.
* After Step 4, the simulation will resume to Step 1.
This simulation is organized into four progressive steps:

1. Define a structure
2. Declare structure variables
3. Write a function that fills or updates a structure
4. Use structures to handle related data

#### How to use the simulation

1. Read the instruction shown in the top panel for the current step.
2. Write the required C code in the editor area.
3. Click **Check Solution** to verify your answer.
4. Compare your code with the ideal solution shown in the right panel.
5. Click **Yes** to continue to the next step.
6. Click **No** if you want to remain on the same step and try again.
7. After Step 4, the simulation returns to Step 1 so you can repeat the full workflow.

#### What each step teaches

1. Step 1 introduces the syntax for defining a structure.
2. Step 2 shows how to declare variables of a structure type and how arrays of structures can be created.
3. Step 3 demonstrates how structures can be passed to functions and updated using member access.
4. Step 4 connects the concept to practical data handling, where a structure is used to store related values together.
6 changes: 4 additions & 2 deletions experiment/references.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
1. [C - Structures information](https://en.wikipedia.org/wiki/Struct_(C_programming_language))
2. [C - Structure coding](https://www.w3schools.com/c/c_structs.php)
1. [C structures and unions](https://en.cppreference.com/w/c/language/struct)
2. [C arrays](https://en.cppreference.com/w/c/language/array)
3. [C typedef](https://en.cppreference.com/w/c/language/typedef)
4. [C dynamic memory management](https://en.cppreference.com/w/c/memory/malloc)
36 changes: 27 additions & 9 deletions experiment/theory.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
In C programming, arrays are useful for storing and working with many values of the same type, such as a list of numbers or characters. However, sometimes you need to keep together different types of information that belong to a single entity. For example, a student's record might include their name (text), roll number (number), gender (character), and stream (text).
In C programming, arrays are useful when you need to store many values of the same type. However, many real-world records contain different kinds of data that belong together. A student record, for example, may include a name, roll number, gender, course, and marks. These values are related, but they are not all of the same type. C structures are designed for exactly this situation.

To handle such cases, C provides structures. A structure is a user-defined data type that allows you to group variables of different types under one name. This makes it easier to organize and manage related data.
A structure is a user-defined data type that groups variables of different data types under one name. This makes programs easier to organize, read, and maintain. Instead of handling each related value separately, you can treat the whole record as one unit.

For example, to store information about students, you can define a structure like this:
For example, a student record can be defined as:

```

struct student_record {
char name[100];
int rollnumber;
char gender;
char stream[100];
float marks;
};
```

This creates a new data type called `student_record` that contains a name, roll number, gender, and stream. You can then create variables of this type:
This definition creates a structure type named `student_record`. You can then declare variables of this type:

```
struct student_record student1, student2;

struct student_record student1;
struct student_record student2;
```

Or, if you want to store records for many students, you can create an array of structures:
If you need to handle many students, you can also create an array of structures:

```
struct student_record students[100];
```

To access or set the values inside a structure, use the dot (`.`) operator. For example:
To access members of a structure, use the dot (`.`) operator:

```

strcpy(student1.name, "Abc");
student1.rollnumber = 24;
student1.gender = 'm';
strcpy(student1.stream, "Computer Science");
student1.marks = 84.5;
```

All the data for a structure is stored together in memory. If you copy one structure variable to another (e.g., `student2 = student1;`), all the fields are copied at once.
Structures are stored as a group of related fields in memory. When one structure variable is assigned to another, all the members are copied together. For example, `student2 = student1;` copies the complete record from `student1` to `student2`.

#### Why structures are useful

Structures are better than arrays when a single logical entity has multiple pieces of information of different types. Arrays store repeated items of the same type, while structures store related items of different types. For that reason, structures are commonly used for records such as students, employees, products, and bank accounts.

#### Nested and typedef structures

Structures can also be nested inside other structures. This is helpful when a record has sub-parts, such as an address inside a student record. In C, the `typedef` keyword is often used to give a shorter and cleaner name to a structure type.

#### Example of practical use

Suppose you want to store and update student details in a program. A structure allows you to pass the full record to a function, update selected fields, and return the updated data in a clear and controlled way. This is why structures are a key part of Computer Programming labs: they help model real-world data logically and efficiently.

Structures are powerful because they let you create complex data types that match real-world information, making your programs easier to write and understand.
Structures are powerful because they let you build custom data types that match the problem you are solving, making your programs easier to write, debug, and extend.
Loading