0% found this document useful (0 votes)
28 views

Assignment 6

The document provides instructions for an assignment on 2D arrays and structures in C programming. It contains 3 problems to solve: 1) create and manipulate an m×n matrix, 2) simulate a war zone using a 2D character array to track soldiers and enemies, and 3) build a menu-driven bookshop management system using structures. Functions must be written to handle tasks like adding/displaying book details, listing books by author/price/publisher, and determining if soldiers can defeat all enemies in the war zone simulation.

Uploaded by

akshat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Assignment 6

The document provides instructions for an assignment on 2D arrays and structures in C programming. It contains 3 problems to solve: 1) create and manipulate an m×n matrix, 2) simulate a war zone using a 2D character array to track soldiers and enemies, and 3) build a menu-driven bookshop management system using structures. Functions must be written to handle tasks like adding/displaying book details, listing books by author/price/publisher, and determining if soldiers can defeat all enemies in the war zone simulation.

Uploaded by

akshat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PDS Lab, Section – 18 , Date: 10th Oct 2023

Assignment – 6 [2D-Arrays & Structures]


-------------------------------------------------------------------------------------------------------------------------------
Instructions
-------------------------------------------------------------------------------------------------------------------------------

1. Create a directory named as Lab-6.


2. Give the name of the program as <p>.c where <p> implies the problem number,
like 1.c, 2.c, 3.c, etc. Store all the programs of this week under this directory.
3. You should upload all .c files (1.c, 2.c, 3.c ....) to the Moodle course web page
latest by 5.00 PM (without penalty). The cutoff time will be till 5.15 PM with a
penalty of 25% on your secured marks (i.e., if you secured 80 marks, after
penalty you will get 60 marks). Beyond 5.15 PM, the moodle system will not allow
you to submit, as a result you will get zero.

---------------------------------------------------------------------------------------------------------------------

1. Write a C program to perform the following : (30M)


a) Take two positive integers m and n from the user and fill up the m×n matrix through
keyboard and print the same.
b) Take another positive integer p (p < (m,n)) from the user and print all possible sub-
matrices of size p×p by scanning the above m×n matrix row-wise. Suppose, if the values
of m, n and p are 5, 7 and 3, the number of possible sub-matrices of size 3×3 in 5×7 are
15.
c) For each p×p square matrix, compute the sum of the boundary elements and print the
same along with the matrix.
d) Determine the maximum sum among all sub-matrices of size p×p, and display the
maximum sum as well as the starting indices (indices of the 1st element) of that sub-
matrix. .

Example : m = 5, n = 7, p = 3.

2 0 8 3 -1 5 10
16 -5 4 9
7 19 20 -8
4 -8 -7 -13
5 9 -7 10 8 9 12

Max sum = 81, Starting indices of the sub-matrix = (1,4)


(30M)
2. There is an on-going war between two countries. Assume there is a war-region or grid in the
form of 2D character matrix. Each entry of the matrix can have 3 alternatives. X-Land, E-
Enemies, S-Solders. Solders (S) can defeat/kill enemies (E) only in vertical and horizontal
directions with respect to their positions. Write a c program to perform the following.
a) Take m, n (positive integers) as an input from the user and fill up the m×n matrix
(grid/war-field) with 3 alternatives (S, E, X) as mentioned above. Display the
contents of the war-region.
b) Write function which takes 2D array as input and compute number of solders and
enemies present in the war-zone.
c) Write a function to compute whether all the enemies can be defeated by solders based
on the existing war-zone situation/condition. If not possible to defeat all enemies,
compute the number of enemies survived.
d) The above two functions to be called from the main() and print the appropriate
information in the main().
Example:
m = 4, n = 4 m = 4, n = 4
XEEX XEEX
XSXX XSXX
XEXX XEXE
XXSX XXSX
Number of solders = 2 Number of solders = 2
Number of Enemies = 3 Number of Enemies = 3
Yes: Solders defeat all enemies. No: One enemy is survived.

3. Write a menu-driven C program to implement the functionality of a book shop. (40M)


The menu options are as follows:
(i) Add book details
(ii) Display book details
(iii) List all books of a given author
(iv) List of number of books in the shop over the given price.
(v) List of books published in a given city.
(vi) List of books from a given publisher with the price above some value.
(vii) Exit.
Use the following structure definitions in implementation:
struct book {char name[100]; char author[100]; publisher p[5]; int price;};
typedef struct {char name[100]; char city[50]; int year;} publisher;
Write separate C functions to carry out each of the tasks mentioned under Menu.
Example:
MENU
Press 1 : Add book details
Press 2 : Display book details
Press 3 : List all books of a given author
Press 4 : List of number of books in the shop over the given price.
Press 5 : List of books published in a given city.
Press 6 : List of books from a given publisher with the price above some value.
Press 7 : Exit.

Enter Your Choice: 1


Add Details of Book
-------------------------------------
Book Name : Algo
Enter Author Name : Aditya
Enter Publication Name : Pearson
Enter Publication City : Pune
Enter Publication Year : 2011
Enter Price : 403

Enter Your Choice: 1


Add Details of Book
-------------------------------------
Book Name : OS
Enter Author Name : Eva
Enter Publication Name : McHill
Enter Publication City : Delhi
Enter Publication Year : 2015
Enter Price : 200

Enter Your Choice: 2


Details of All Books
-----------------------------------------------------------
Book Name Author Name Price
------------------------------------------------------------
Algo Aditya 403
OS Eva 200

You might also like