part iII: project
Problem 1

a- Compute the median of a data file. The median is the number that has the same number of data elements greater than the number as there are less than the number. For purposes of this problem, you are to assume that the data is sorted (that is, is in increasing order). The median is the middle element of the file if there are an odd number of elements. You will need to open the file, count the members, close the file and calculate the location of the middle of the file, open the file again (recall the “start over” discussion in this chapter), count up to the file entries you need, and calculate the middle.

b- For a sorted file, a quartile is one of three numbers: the first has one-fourth the data values less than or equal to it, one-fourth the data values between the first and second numbers, one-fourth the data points between the second and the third, and one-fourth above the third quartile. Find the three quartiles for the data file you used for part (a).

Hint: you should recognize that having done part (a) you have one-third of your job done. (You have the second quartile already.) You also should recognize that you have done almost all the work toward finding the other two quartiles as well.

Problem 2

Write a program to compute numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student’s last name, then one space, then the student’s first name, then one space, then ten quiz scores all on one line. The quiz scores are whole numbers and are separated by one space. Your program will take its input from this file and send its output to a second file. The data in the output file will be the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student’s ten quiz scores. If this is being done as a class assignment, obtain the file names from your instructor. Use at least one function that has file streams as all or some of its arguments.

Problem 3

Enhance the program you wrote for (Problem 2) in all the following ways.
a- The list of quiz scores on each line will contain ten of fewer quiz scores. (If there are fewer than ten quiz scores, which means that the student missed one or more quizzes.) The average score is still the sum of the quiz scores divided by 10. This amounts to giving the student a 0 for any missed quiz.
b- The output file will contain a line (or lines) at the beginning of the file explaining the output. Use formatting instructions to make the layout neat and easy to read.
c- After placing the desired output in an output file, your program will close all files and then copy the contents of the “output” file to the “input” file so that the net effect is to change the contents of the input file.
Use at least two functions that have file streams as all or some of their arguments. If this is being done as a class assignment, obtain the file names from your instruction.

Problem 4

Write a program that will correct a C++ program that has errors in which operator, << or >>, it uses with cin and cout. The program replaces each (incorrect) occurrence of

cin<<

With the corrected version

cin>>

And each (incorrect) occurrence of

cout>>

With the corrected version

cout<<

For an easier version, assume that there is always exactly one blank space between any occurrence of cin and a following <<, and similarly assume that there is always exactly one blank space between each occurrence of cout and a following >>.

For a harder version, allow for the possibility that there may be any number of blanks, even zero blanks, between cin and << and between cout and >>. In this harder case, the replacement corrected version has only one blank between the cin and cout and the following operator. The program to be corrected is in one file and the corrected version is output to a second file. Your program should define a function that is called with the input- and output-file streams as arguments.

If this is being done as a class assignment, obtain the file names from your instructor and ask your instructor whether you should do the easier version or the harder version.

Hint: Even If you are doing the harder version, you will probably find it easier and quicker to first do the easier version and then modify your program so that it performs the harder task.

Problem 5

This program numbers the lines found in a text file. Write a program that reads text from a file and outputs each line to the screen and to another file preceded by a line number. Print the line number at the start of the line and right-adjusted in a field of three spaces. Follow the line number with a colon, then one space, then the text of the line. You should get a character at a time, and write code to ignore leading blanks on each line. You may assume that the lines are short enough to fit within a line on the screen. Otherwise, allow default printer or screen output behavior in the line is too long (that is, wrap or truncate).

A somewhat harder version determines the number of spaces needed in the field for the line numbers by counting lines before processing the lines of the file. This version of the program should insert a new line after the last complete word that will fit within a 72-character line.


Problem 6

Information about the status of football teams taking part in a league has been stored in a binary file so that for each team there is an entry in the file. An entry contains the team’s name, the points it has, and the number of goals scored for and against. Entries in the file are in arbitrary order.

Write a program that sorts the file so that the team with most points comes first and the team with least points comes last. If several teams have the same number of points, the team with the best goal average should be placed in alphabetical order. Tip: Read all the teams into an array, sort it, then write it out in the file.

Problem 7


Consider a graphics system that has classes for various-rectangles, squares, triangles, circles, and so on. For example, a rectangle might have data members for height, width, and a center point, while a square and circle might have only a center point and an edge length or radius, respectively. In a well designed system, these would be derived from a common class, Figure. You are to implement such a system.

The class Figure is the base class. You should add only Rectangle and Triangle classes derived from Figure. Each class has stubs for member functions erase and draw. Each of these member functions outputs a message telling what function has been called and what the class of the calling object is. Since there are just stubs, they do nothing more than output this message. The member function center calls the erase and draw functions to erase and redraw the figure at the center. Since you have only stubs for erase and draw, center will not do “centering” but will call the member functions erase and draw. Also add an output message in the member function center that announces that center id being called. The member functions should take no arguments.

There are three parts to this project:

a- Write the class definitions using no virtual functions. Compile and test
b- Make the base class member functions virtual. Compile and test.
c- Explain the difference in results.

Recommended Answers

All 8 Replies

I can help you, see that link called 'the basics' in my signature ? I recommend you read that.

hi
plz help i need it on c++ language

plz i agree

I would recommend making a Google search for open source graphic engines. There are quite a few good ones out there, where I'm sure you'll find the answers to your project.

<<threads merged>>

part iII: project
Problem 1

a- Compute the median of a data file. The median is the number that has the same number of data elements greater than the number as there are less than the number. For purposes of this problem, you are to assume that the data is sorted (that is, is in increasing order). The median is the middle element of the file if there are an odd number of elements. You will need to open the file, count the members, close the file and calculate the location of the middle of the file, open the file again (recall the “start over” discussion in this chapter), count up to the file entries you need, and calculate the middle.

b- For a sorted file, a quartile is one of three numbers: the first has one-fourth the data values less than or equal to it, one-fourth the data values between the first and second numbers, one-fourth the data points between the second and the third, and one-fourth above the third quartile. Find the three quartiles for the data file you used for part (a).

Hint: you should recognize that having done part (a) you have one-third of your job done. (You have the second quartile already.) You also should recognize that you have done almost all the work toward finding the other two quartiles as well.

Problem 2

Write a program to compute numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student’s last name, then one space, then the student’s first name, then one space, then ten quiz scores all on one line. The quiz scores are whole numbers and are separated by one space. Your program will take its input from this file and send its output to a second file. The data in the output file will be the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student’s ten quiz scores. If this is being done as a class assignment, obtain the file names from your instructor. Use at least one function that has file streams as all or some of its arguments.

Problem 3

Enhance the program you wrote for (Problem 2) in all the following ways.
a- The list of quiz scores on each line will contain ten of fewer quiz scores. (If there are fewer than ten quiz scores, which means that the student missed one or more quizzes.) The average score is still the sum of the quiz scores divided by 10. This amounts to giving the student a 0 for any missed quiz.
b- The output file will contain a line (or lines) at the beginning of the file explaining the output. Use formatting instructions to make the layout neat and easy to read.
c- After placing the desired output in an output file, your program will close all files and then copy the contents of the “output” file to the “input” file so that the net effect is to change the contents of the input file.
Use at least two functions that have file streams as all or some of their arguments. If this is being done as a class assignment, obtain the file names from your instruction.

Problem 4

Write a program that will correct a C++ program that has errors in which operator, << or >>, it uses with cin and cout. The program replaces each (incorrect) occurrence of

cin<<

With the corrected version

cin>>

And each (incorrect) occurrence of

cout>>

With the corrected version

cout<<

For an easier version, assume that there is always exactly one blank space between any occurrence of cin and a following <<, and similarly assume that there is always exactly one blank space between each occurrence of cout and a following >>.

For a harder version, allow for the possibility that there may be any number of blanks, even zero blanks, between cin and << and between cout and >>. In this harder case, the replacement corrected version has only one blank between the cin and cout and the following operator. The program to be corrected is in one file and the corrected version is output to a second file. Your program should define a function that is called with the input- and output-file streams as arguments.

If this is being done as a class assignment, obtain the file names from your instructor and ask your instructor whether you should do the easier version or the harder version.

Hint: Even If you are doing the harder version, you will probably find it easier and quicker to first do the easier version and then modify your program so that it performs the harder task.

Problem 5

This program numbers the lines found in a text file. Write a program that reads text from a file and outputs each line to the screen and to another file preceded by a line number. Print the line number at the start of the line and right-adjusted in a field of three spaces. Follow the line number with a colon, then one space, then the text of the line. You should get a character at a time, and write code to ignore leading blanks on each line. You may assume that the lines are short enough to fit within a line on the screen. Otherwise, allow default printer or screen output behavior in the line is too long (that is, wrap or truncate).

A somewhat harder version determines the number of spaces needed in the field for the line numbers by counting lines before processing the lines of the file. This version of the program should insert a new line after the last complete word that will fit within a 72-character line.


Problem 6

Information about the status of football teams taking part in a league has been stored in a binary file so that for each team there is an entry in the file. An entry contains the team’s name, the points it has, and the number of goals scored for and against. Entries in the file are in arbitrary order.

Write a program that sorts the file so that the team with most points comes first and the team with least points comes last. If several teams have the same number of points, the team with the best goal average should be placed in alphabetical order. Tip: Read all the teams into an array, sort it, then write it out in the file.

Problem 7


Consider a graphics system that has classes for various-rectangles, squares, triangles, circles, and so on. For example, a rectangle might have data members for height, width, and a center point, while a square and circle might have only a center point and an edge length or radius, respectively. In a well designed system, these would be derived from a common class, Figure. You are to implement such a system.

The class Figure is the base class. You should add only Rectangle and Triangle classes derived from Figure. Each class has stubs for member functions erase and draw. Each of these member functions outputs a message telling what function has been called and what the class of the calling object is. Since there are just stubs, they do nothing more than output this message. The member function center calls the erase and draw functions to erase and redraw the figure at the center. Since you have only stubs for erase and draw, center will not do “centering” but will call the member functions erase and draw. Also add an output message in the member function center that announces that center id being called. The member functions should take no arguments.

There are three parts to this project:

a- Write the class definitions using no virtual functions. Compile and test
b- Make the base class member functions virtual. Compile and test.
c- Explain the difference in results.








moe1983, What tools have you been given to complete this project ?

Read Announcement Please.

Nobody will help you unless you show what you have done upto now. We do not do others homework.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.