Assignment-8

divider
Question-1

Q1. “Story.txt” file contains the following story. Read the content and display it on the screen using a C program:


Story.txt
One night four college students were out partying late at night and didn’t study for the test which was scheduled for the next day. In the morning, they thought of a plan. They made themselves look dirty with grease and dirt. Then they went to the Dean and said they had gone out to a wedding last night and on their way back the tire of their car burst and they had to push the car all the way back. So they were in no condition to take the test. The Dean thought for a minute and said they can have the re-test after 3 days. They thanked him and said they will be ready by that time. On the third day, they appeared before the Dean. The Dean said that as this was a Special Condition Test, all four were required to sit in separate classrooms for the test. They all agreed as they had prepared well in the last 3 days. The Test consisted of only 2 questions with the total of 100 Points:
1) Your Name? __________ (1 Points)
2) Which tire burst? __________ (99 Points)
Options – (a) Front Left (b) Front Right (c) Back Left (d) Back Right
Question-2

Q2. Read the file Story.txt (in Q1) and display the contents on screen line by line using C program.

Question-3

Q3. Write a C program to illustrate how to import another file using #include. For example, few math functions are defined in a file “MyMathFunctions.c”. Your program should start with #include”MyMathFunctions.c” etc. and call the functions defined in that file.

Question-4

Q4. Can you open a file both for reading and writing? What are the pros and cons of doing this?

Question-5

Q5. What is the random access of a file? What is a file pointer? Practice functions seekp(), seekg(), tellp() and tellg() while reading and writing into a file.

Question-6

Q6. Write a C program to count:
a) Number of characters in a file
b) Number of words in a file
c) Number of lines in a file

Question-7

Q7. How would you copy the contents of a file into another file using a C program?

Question-8

Q8. What are the command line arguments? Illustrate the usage of int main(int argc, char *argv[]).

Question-9

Q9. Read marks500.txt to find min and max of the marks. This file can be found at on the lab assignment page: https://sites.google.com/a/thapar.edu/uta-007/ues103/lab-assignments?authuser=0

Question-10

Q10. Read marks500.txt. Which roll number is the topper and print the roll numbers who failed (marks below 33)

Question-11

Q11. Read marks500.txt. Find average and standard deviation of these 500 marks and save this into a new file MarksStats.txt

Question-12

Q12. Make a big notepad file of thousands entries and then do some interesting data analysis. Larger text files can be found on Google for example https://archive.ics.uci.edu/datasets