You are on page 1of 3

MILITARY INSTITUTE OF SCIENCE AND TECHNOLOGY

Department of Industrial and Production Engineering (IPE)


Course Code: CSE281
Course Name: Computer Programming
Class Test-03 Spring 2023

Total Marks: 20 Time:30 mins

1. In MIST, a talented and ambitious computer science student named ‘Asir’ is 12


known for his passion for programming in C. As the semester nears its end, his
teacher announces an exciting challenge—the creation of a complex
memory-based maze using structures and pointers.

Eager to prove his skills, Asir immerses himself in designing the most intricate
and challenging maze. He spends countless hours carefully constructing the
maze's layout, utilizing structures to represent each section, and implementing
pointers to connect different paths.

Upon completion, Asir invites his classmates and the teacher to embark on a
thrilling adventure through the memory maze. The participants are instructed to
navigate through the maze using their knowledge of structures and pointers to
find a hidden treasure at the maze's heart.

As the group enters the maze, they encounter a labyrinth of interconnected


memory blocks, each representing a different section of the puzzle. Asir's
meticulous design ensures that solving each section requires manipulating
pointers and navigating the maze's complex structure.

The group must employ their understanding of structures and pointers to analyze
the maze's memory blocks, determining the correct paths to progress. They face
challenges that demand logical thinking, memory management, and careful
traversal of the maze's interconnected pathways.

Along the way, the participants uncover hidden clues and keys, discovering that
solving puzzles within specific memory blocks grants access to previously
inaccessible areas. These puzzles intricately tie together the concepts of
structures and pointers, rewarding those who apply their knowledge effectively.

As the group inches closer to the maze's center, tension builds, and the challenges
become more demanding. They must skillfully manipulate pointers to unlock
secret passages, rearrange memory blocks, and traverse the ever-shifting maze
structure.
Finally, after numerous trials and tribulations, the group reaches the heart of the
maze—a virtual treasure room filled with recognition and a sense of
accomplishment. Asir's classmates applaud their dedication and the clever use of
structures and pointers to create such an immersive and challenging experience.

The memory maze not only showcased Asir's programming prowess but also
served as an educational journey for all participants. It deepened their
understanding of memory management, data structures, and the importance of
pointer manipulation in C programming.

The experience strengthens the bond between Asir and their classmates as they
celebrate their shared triumph. The memory maze remains a testament to their
collective knowledge and a reminder of the power of structures and pointers to
create engaging and intellectually stimulating experiences.

"The Memory Maze" concludes with Asir and their classmates reflecting on the
journey, grateful for the practical application of their programming skills and the
camaraderie forged through the adventure. They leave the maze with a newfound
appreciation for the complexities and possibilities offered by structures and
pointers in the world of programming.

a) What is the purpose of using structures in C programming? Provide an


example of how structures can be defined and used.

b) Explain the usage of pointers based on the scenario.

c) Reflecting on the plot, compare the performance of structures and pointers.

2. Observe the code carefully and answer the following questions: 8

#include <stdio.h>
#include <string.h>

struct Car {
char brand[50];
int year;
char model[50];
double price;
};

void increasePrice(struct Car* car) {


(*car).price *= 1.1; // Increase price by 10%
}
void printCarDetails(struct Car* car) {
printf("Brand: %s\n", (*car).brand);
printf("Year: %d\n", (*car).year);
printf("Model: %s\n", (*car).model);
printf("Price: $%.2f\n", (*car).price);
}

int main() {
struct Car car1 = {"Tesla", 2022, "Model S", 79999.99};
struct Car* carPtr = &car1;

// Print car details before price increase


printf("--- Car Details (Before Price Increase) ---\n");
printCarDetails(carPtr);

// Increase car price


increasePrice(carPtr);

// Print car details after price increase


printf("\n--- Car Details (After Price Increase) ---\n");
printCarDetails(carPtr);

// Questions for Students


printf("\n--- Guess the Output ---\n");
printf("1. What is the car's brand?\n");
printf("2. What is the car's manufacturing year?\n");
printf("3. What is the car's model?\n");
printf("4. What is the car's price before the price increase?\n");
printf("5. What is the car's price after the price increase?\n");
return 0;
}

You might also like