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

Project Definitions 5

Uploaded by

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

Project Definitions 5

Uploaded by

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

Project definitions for the Open Elective

Instructions:
1) Please note the word in italic is to be replaced by the actual value. Where ever used, file
indicates file name.
2) Please write the algorithm in a text file and submit it for review. This is to validate that you have
correctly understood the problem statement. This also results in your logic getting reviewed
before you start coding
3) The project to be:
a) coded in C Language in Linux environment.
b) A directory has to be creates in your home directory (/home/your_user_id) and the project
related files have to be placed in that directory. Ensure the source files have the .c extension
and header files .h extension. Also the names of the file should have no spaces in them.
c) use the coding guidelines indicated in the document “Coding standards.pdf” while writing
the programs. THIS IS VERY IMPORTANT.
d) write the problem statement as a comment at the top of the file.
4) Submitted programs should compile with no ERRORs or WARNINGS with gcc compiler on
Linux Ubuntu 22.04.
5) Test your programs before submitting.
6) The last date for submission is _________________

1. Project 1
Project has to do the following:
a. Read the complete contents of a file specified on the command line as
follows:
./a.out file (e.g ./a.out words.txt)
b. Count the number of words in the file and display on the screen:
word count = …
c. Keep a count of the various lengths of each word in the file.
d. Print a vertical histogram of the length of words using “*” character as
the bar in the following manner:
example: if the number of 1, 2 and 3 letter words are as follows:
1 letter word = 2
2 letter word = 4
3 letter word = 7
4 letter word = 0
5 letter word = 3
then, display the histogram in the following manner:
*
*
*
* *
* * *
* * * *
* * * *
2. Project 2
Project has to do the following:
a. Read the complete contents of a file specified on the command line as
follows:
./a.out file (e.g ./a.out lines.txt)
b. Count the number of lines in the file, and display it on the screen:
line count = …
c. Print all lines less than 80 characters.
d. Fold all lines greater than 80 characters into 2 or more lines ensuring
that:
i. all lines are less than 80 characters
ii. split the line after last non-blank character that occurs before
the 80th character.

3. Project 3
The project has to do the following:
a. Take a filename as command line argument as shown:
./a.out file (e.g. ./a.out students.txt)
The file contains the name of the student and the marks in science and
maths as shown below:
student-name1 sceince-marks1 maths-marks1
student-name2 sceince-marks2 maths-marks2

sample input:
Annie 74 85
Adam 84 75

b. Open the file for reading.


c. Using fgets(…), read each line from the file and store in:
struct student {
char *name;
float science;
float maths;
};
hint: You may need to open the file twice (or use the library function
fseek () or rewind ()):
i. to get the number of lines in the file.
ii. to read the data and store it.
Alternately instead of opening and closing the file twice, you may use
rewind(…) or fseek ().
You will also need to handle invalid/insufficient input by erroring out.
d. Print as output:
i. The names and marks scored by each student for each subject
ii. The subject names and the average marks

sample output:
Annie:
Science = 74
Maths = 85
Adam:
Science = 84
Maths = 75


Average marks:
Science: 51.388889
Maths: 54.000000

e. provide a way to sort the student database in ascending/descending order


based on:
i. names (using the ASCII value of the characters)
ii. Maths marks
iii. Science mark.
f. Free the allocated memory.

4. Project 4
The project has to do the following:
a. Take a set of options and filename as command line argument:
./a.out [-w|-c|-l] file
where:
-w : indicates calculate word count
-c : indicates calculate character count
-l : indicates calculate line count
Please note –w, -c, -l can be optional or multiple options can also be
specified as this:
./a.out ex2.c
./a.out –wlc ex2.c
./a.out –w –l -c ex2.c
./a.out –wl ex2.c
./a.out –w ex2.c

b. Calculate the number of characters, words or lines in the file passed as


argument.
c. Print output in the following manner if NO options are specified:
<line-count> <word-count> <character-count> <file-name>
d. Based on the input options –c/w/l, certain values can be suppressed as in
the examples below:
Input:./a.out –wlc ex2.c OR ./a.out –w –l –c ex2.c
Output: 34 73 452 ex2.c

Input:./a.out –wl ex2.c OR ./a.out –w –l ex2.c


Output: 34 73 ex2.c

Input:./a.out –w ex2.c
Output: 73 ex2.c

e. Please display the appropriate messages when sufficient arguments are not
specified. Error messages to be always written to STDERR.
Example: when the following command is given with no other command
line arguments:
./a.out
Print: usage: ./a.out [-w | -c | -l] <file_name>

5. Project 5
"RXSR" is a 32 bit register at offset 0. It is made up of the following fields:

bit positions 31 - 7 6-5 4 3 2 1 0


fields RSVD PS OE BI PE FE DR

Please write a test application with main function that tests the register field
read and write for the register "RXSR".
To help you in this task, the following files have been provided in
lib_folder.zip:

a) reg_setup.h: This header file contains the prototypes of the following


functions:
• void reg_setup (); // initializes the registers
• void reg_wr32 (int off, unsigned in val); // writes a
32 bit data into the register at the specified offset
• unsigned int reg_rd32 (int off); // reads a 32 bit
data from the register at the specified offset
• void disp_all_regs (); // displays the registers with
fields using ASCII characters
• void disp_reg (int off); // displays the register at
offset off using ASCII characters
b) libregsim64.a: A library file that needs to be linked while compiling the
application on a 64 bit system. This library contains the implementation of
all the function mentioned above.
Use the following command to compile with the library:
gcc <application-fil>e -L . -l regsim64

Example: If your test application file is test.c, use the command:


gcc test.c -L . -l regsim64

6. Project 6
"ULCR" is a 32 bit register at offset 1. It is made up of the following fields:

bit positions 12 - 31 7 6 5-4 3 2 1-0


fields Reserved DLAB BC PS PE SB WLS

Please write a test application with main function that tests the register field
read and write for the register "ULCR".
To help you in this task, the following files have been provided in
lib_folder.zip:

c) reg_setup.h: This header file contains the prototypes of the following


functions:
• void reg_setup (); // initializes the registers
• void reg_wr32 (int off, unsigned in val); // writes a
32 bit data into the register at the specified offset
• unsigned int reg_rd32 (int off); // reads a 32 bit
data from the register at the specified offset
• void disp_all_regs (); // displays the registers with
fields using ASCII characters
• void disp_reg (int off); // displays the register at
offset off using ASCII characters
d) libregsim64.a: A library file that needs to be linked while compiling the
application on a 64 bit system. This library contains the implementation of
all the function mentioned above.

Use the following command to compile with the library:


gcc <application-fil>e -L . -l regsim64

Example: If your test application file is test.c, use the command:


gcc test.c -L . -l regsim64

7. Project 7
Read lines from a file and store them in a two dimensional char array created
using a char **. The file will be specified as a command line argument.
(example:./a.out file)

The program should work as follows:


Display the first 24 lines and display a “:” on the 25th line and wait for input
from the user. Valid inputs are:
• space:- this will make the program display the next 24 lines and again display the “:”
and wait. If end of file, i.e the last page is reached when space is pressed, do nothing
• q:- this will make the program quit the program.

If the file has 24 lines or less number of lines, display the lines and wait on the
colon “:” prompt.

This is a simplified implementation of the Linux command “less”.

8. Project 8
Write a program detab, that replaces all the tabs in an input file (specified as a
command line argument) with 4 blank spaces.

9. Project 9
Write a program remove all comments from a C program. There will be no
nested comments (comment inside a comment). Make sure both multi-line
comments (/* … */) and single line comments (// …) are handled.

10. Project 10
Write a program to check a C program to see whether there are any unmatched
braces (curly brackets). Remember that there can be braces inside a pair of
braces. The C program file will be provided as a command line argument

11. Project 11
Write a program to check a C program to see whether there are any unmatched
square brackets. The C program file will be provided as a command line
argument

12. Project 12
Write a program to check a C program to see whether there are any unmatched
parentheses. Remember that there can be parentheses inside a pair of
parentheses. The C program file will be provided as a command line argument

13. Project 13
Write a C program to implement all arithmetic operations on complex numbers.
It should be a menu driven program that displays options for all the arithmetic
operations and also for exiting the program.

The option entered by the user should be used as an index into an array of
function pointers that contains the addresses of the arithmetic operation
functions. So the arithmetic operation will be carried out using these function
pointers.

NOTE: Remember that complex numbers may be entered in rectangular or polar form and
the program should keep track of the format in which the complex number has been entered.

You might also like