Opening a file reading from file writing to a file and


Computer Programming

Objectives:

1. Opening a file, reading from file, writing to a file and closing a file.

2. Sequential access files handling.

3. Practice C++ programming problems.

Note: Carefully read the following instructions (Each instruction contains a weightage)

1. There must be a block of comments at start of every question's code by students; the block should contain brief description about functionality of code.

2. Proper indentation of code is essential

3. Write a C++ statement(s) for each of the following task one after the other, in the same order.

4. Make a Microsoft Word file and past all of your C++ code with screenshot of outputs in MS word.

5. First think about statement problems and then write/draw your logic on copy.

6. After copy pencil work, code the problem statement on MS Studio C++ compiler.

7. At the end when you done your today lab tasks , attached all created C++ files+ MS word file and make your submission on slate.

PROBLEM 1.

A class instructor found that the class he is teaching have a habit of not doing assignments by themselves. He looked into all the previous assignment submissions and found a very interesting pattern that, the students take assignment only from their neighbor roll no’s. and submit it as it is but the tricky part is that odd roll no’s only copy it from their odd neighbors and even roll no’s copy it only from their even neighbors. E.g. if a student has roll no. 23, the possibility is that he/she can copy the assignment from roll no 21 or 25 as they are the odd  neighbor  of roll no 23. Similarly even neighbors of roll no. 2 are 0 and 4.

The instructor evaluates the assignments and assigns marks as floating point values. The instructor knows that if 2 students have submitted the same assignment they will get same marks. So the instructor quickly wants to find out how many students are involved in copy-case and what are their roll no’s. Unfortunately the instructor doesn’t know the programming and needs your help. The instructor will provide you the data in below format.

First line of input contains an integer N where N should be greater than 0 and less than 100, denoting the number of students. Then following N space separated floating point values in next line representing each student’s marks in assignment. You can assume that the student roll no’s start from 0 and the student’s assignment marks is input and it is sorted roll no wise. So first entry of marks is off roll no. 0 and the last entry will have roll # (N-1).

You are to read assignment marks of all the students and store them in an array and the indexes of the array would represent roll no’s.

Now your task is to find out how many students are involved in copy case and what are their roll no’s. Your program should find this based on the criteria of odd and even neighbors that instructor mentioned above. The example below will give you the complete idea.

Example:

Input:

8

3.5  9.4  13.42  9.4  45.56  45.56  45.56  3.5 

Array mapping:

Your array should look like this:

Array Index (Roll NO’s)

0

1

2

3

4

5

6

7

Assignment Marks

3.5

9.4

13.42

9.4

45.56

45.56

45.56

3.5

 Output:

Count of students involved in copy case: 4

Roll no’s of students involved: 1, 3, 4, and 6

PROBLEM 2.

Write a C++ program to sort an array of 10 elements by bubble sort algorithm. First you have to initialize array with random numbers less than 15 then you will sort it in ascending order.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Opening a file reading from file writing to a file and
Reference No:- TGS01595123

Now Priced at $20 (50% Discount)

Recommended (91%)

Rated (4.3/5)