Lab6: I/O and Arrays

E

Lab6 COMP3010

Assigned: March 26, 2014 1 Due: April 13, 2014
HW 6: I/O and Arrays
COMP 3010
Assigned on: March 26, 2014 Due on: April 13, 2014
Problem 1
(a) Compute the median of data file. The median is the number that has the same
number of data elements greater than the numbers 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, or the average of the two middle elements if the file has an
even 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.
While testing construct several files on your own, including one with an even number
of data points, increasing, and one with an odd number, also increasing.
When you are confident your program is correct, modify it to read data from a file
called dataMedianQuartiles
(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 that takes its input from a file of numbers of type double.
The program outputs to the screen the average and standard deviation of the numbers
in the file. The file contains nothing but numbers of type double separated by blanks
and/or line breaks. The standard deviation of a list of numbers n1, n2, n3, and so forth
is defined as the square root of the average of the following numbers:
(n1 − a)2
, (n2 − a)2
, (n3 − a)2
and so forth
The number a is the average of the numbers n1, n2, n3, and so forth.
Your program should read input from a file called stdDev.
Hint: Write your program so that it first reads the entire file and computes the average of
all the numbers, and then closes the file, then reopens the file and computes the standard
deviation.
HW 6: I/O and Arrays
Assigned: March 26, 2014 2 Due: April 13, 2014
Problem 3 Write a program that merges the numbers in two files and writes all the
numbers into a third file. Your program takes input from two different files and writes
its output to a third file. Each input file contains a list of numbers of type int in sorted
order from the smallest to the largest. After the program is run, the output file will
contain all the numbers in the two input files in one longer list in sorted order from
smallest to largest. Your program should define a function that is called with the two
input-file streams and the output-file stream as three arguments.
Your program needs to read input data from files merge1 and merge2 and write output
to file merged.
Problem 4 Hexadecimal numerals are integers written in base 16. The 16 digits used are
’0’ through ’9’ plus ’a’ for the “digit 10”, ’b’ for the “digit 11”, ’c’ for the “digit 12”,
’d’ for the “digit 13”, ’e’ for the “digit 14”, and ’f’ for the “digit 15”. For example, the
hexadecimal numeral d is the same as base 10 numeral 13 and the hexadecimal numeral
1d is the same as the base 10 numeral 29. Write a C++ program to perform addition
of two hexadecimal numerals each with up to 10 digits. if the result of the addition is
more than 10 digits long, then simply give the output message “Addition Overflow” and
not the result of the addition. Use arrays to store hexadecimal numerals as arrays of
characters. Include a loop to repeat this calculation for new numbers until the user says
she or he wants to end the program.
Problem 5 Write a function called delete_repeats that has a partially filled array of
characters as a formal parameter and that deletes all repeated letters from the array.
Since a partially filled array requires two arguments, the function will actually have two
formal parameters: an array parameter and a formal parameter of type int that gives
the number of array positions used. When a letter is deleted, the remaining letters are
moved forward to fill in the gap. This will create empty positions at the end of the array
so that less of the array is used. Since the formal parameter is a partially filled array, a
second formal parameter of type int will tell how many array positions are filled. This
second formal parameter will be a call-by-reference parameter and will be changed to
show how much of the array is used after the repeated letters are deleted.
For example, consider the following code:
char a[10];
a[0] = ’a’;
a[l] = ’b’;
a[2] = ’a’;
a[3] = ’c’;
int size = 4;
delete_repeats(a, size);
HW 6: I/O and Arrays
Assigned: March 26, 2014 3 Due: April 13, 2014
After this code is executed, the value of a[0] is ’a’, the value of a[1] is ’b’, the value of
a[2] is ’c’, and the value of size is 3. (The value of a[3] is no longer of any concern,
since the partially filled array no longer uses this indexed variable.)
You may assume that the partially filled array contains only lowercase letters. Embed
your function in a suitable test program.

Recomendados

Bc0038– data structure using c von
Bc0038– data structure using cBc0038– data structure using c
Bc0038– data structure using chayerpa
502 views6 Folien
Unraveling The Meaning From COVID-19 Dataset Using Python – A Tutorial for be... von
Unraveling The Meaning From COVID-19 Dataset Using Python – A Tutorial for be...Unraveling The Meaning From COVID-19 Dataset Using Python – A Tutorial for be...
Unraveling The Meaning From COVID-19 Dataset Using Python – A Tutorial for be...Kavika Roy
48 views16 Folien
Vlookup von
VlookupVlookup
VlookupMelissa Radi, PHR
111 views1 Folie
C programming session 07 von
C programming session 07C programming session 07
C programming session 07Dushmanta Nath
591 views7 Folien
Advanced formula von
Advanced formulaAdvanced formula
Advanced formulaMaymay027
141 views16 Folien
Arrays in c++ von
Arrays in c++Arrays in c++
Arrays in c++Asaye Dilbo
227 views10 Folien

Más contenido relacionado

Was ist angesagt?

Fundamentals of Pointers in C von
Fundamentals of Pointers in CFundamentals of Pointers in C
Fundamentals of Pointers in CShivanshuVerma11
641 views16 Folien
Excel advanced formulas and functions i-school tutorials von
Excel  advanced formulas and functions   i-school tutorialsExcel  advanced formulas and functions   i-school tutorials
Excel advanced formulas and functions i-school tutorialstechie_govind
262 views5 Folien
Pointers in c v5 12102017 1 von
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1tanmaymodi4
666 views32 Folien
MS excel - match function von
MS excel - match functionMS excel - match function
MS excel - match functionVincent Segondo
572 views14 Folien
User defined data type von
User defined data typeUser defined data type
User defined data typeAmit Kapoor
4.7K views10 Folien
Ch13 von
Ch13Ch13
Ch13Arriz San Juan
456 views57 Folien

Was ist angesagt?(19)

Excel advanced formulas and functions i-school tutorials von techie_govind
Excel  advanced formulas and functions   i-school tutorialsExcel  advanced formulas and functions   i-school tutorials
Excel advanced formulas and functions i-school tutorials
techie_govind262 views
Pointers in c v5 12102017 1 von tanmaymodi4
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
tanmaymodi4666 views
User defined data type von Amit Kapoor
User defined data typeUser defined data type
User defined data type
Amit Kapoor4.7K views
Doubly linked list von Fahd Allebdi
Doubly linked listDoubly linked list
Doubly linked list
Fahd Allebdi14.9K views
Spreadsheet formulas ppt (1) von Tammy Carter
Spreadsheet formulas ppt (1)Spreadsheet formulas ppt (1)
Spreadsheet formulas ppt (1)
Tammy Carter5.2K views
Statistics 141 homework 6 complete solutions correct answers key von Song Love
Statistics 141 homework 6 complete solutions correct answers keyStatistics 141 homework 6 complete solutions correct answers key
Statistics 141 homework 6 complete solutions correct answers key
Song Love44 views
Paper talk (presented by Prof. Ludaescher), WORKS workshop, 2010 von Paolo Missier
Paper talk (presented by Prof. Ludaescher), WORKS workshop, 2010Paper talk (presented by Prof. Ludaescher), WORKS workshop, 2010
Paper talk (presented by Prof. Ludaescher), WORKS workshop, 2010
Paolo Missier378 views
Linked list (introduction) 1 von DrSudeshna
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
DrSudeshna22 views
data structures and algorithms Unit 1 von infanciaj
data structures and algorithms Unit 1data structures and algorithms Unit 1
data structures and algorithms Unit 1
infanciaj19 views
Pointers in C Language von madan reddy
Pointers in C LanguagePointers in C Language
Pointers in C Language
madan reddy251 views

Similar a Lab6: I/O and Arrays

Input-output von
Input-outputInput-output
Input-outputneda marie maramo
1K views38 Folien
You are going to write a program that changes a decimal number into .pdf von
You are going to write a program that changes a decimal number into .pdfYou are going to write a program that changes a decimal number into .pdf
You are going to write a program that changes a decimal number into .pdfarjunhassan8
2 views3 Folien
R-Language-Lab-Manual-lab-1.pdf von
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfKabilaArun
11 views33 Folien
R-Language-Lab-Manual-lab-1.pdf von
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfDrGSakthiGovindaraju
50 views33 Folien
R-Language-Lab-Manual-lab-1.pdf von
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfattalurilalitha
3 views33 Folien
CS10 Python Programming Homework 4 40 points Lists, Tupl.docx von
CS10 Python Programming Homework 4 40 points Lists, Tupl.docxCS10 Python Programming Homework 4 40 points Lists, Tupl.docx
CS10 Python Programming Homework 4 40 points Lists, Tupl.docxmydrynan
2 views8 Folien

Similar a Lab6: I/O and Arrays(20)

You are going to write a program that changes a decimal number into .pdf von arjunhassan8
You are going to write a program that changes a decimal number into .pdfYou are going to write a program that changes a decimal number into .pdf
You are going to write a program that changes a decimal number into .pdf
arjunhassan82 views
R-Language-Lab-Manual-lab-1.pdf von KabilaArun
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
KabilaArun11 views
CS10 Python Programming Homework 4 40 points Lists, Tupl.docx von mydrynan
CS10 Python Programming Homework 4 40 points Lists, Tupl.docxCS10 Python Programming Homework 4 40 points Lists, Tupl.docx
CS10 Python Programming Homework 4 40 points Lists, Tupl.docx
mydrynan2 views
COMP 2103X1 Assignment 6Due Thursday, March 2 by 700 PM.docx von donnajames55
COMP 2103X1 Assignment 6Due Thursday, March 2 by 700 PM.docxCOMP 2103X1 Assignment 6Due Thursday, March 2 by 700 PM.docx
COMP 2103X1 Assignment 6Due Thursday, March 2 by 700 PM.docx
donnajames552 views
Mmt 001 von sujatam8
Mmt 001Mmt 001
Mmt 001
sujatam8506 views
Use Python This program must use a loop and an accumulation pattern to.docx von StewartyUMGlovern
Use Python This program must use a loop and an accumulation pattern to.docxUse Python This program must use a loop and an accumulation pattern to.docx
Use Python This program must use a loop and an accumulation pattern to.docx
[removed]DevelopingTechnical Software As.docx von lanagore871
[removed]DevelopingTechnical Software As.docx[removed]DevelopingTechnical Software As.docx
[removed]DevelopingTechnical Software As.docx
lanagore8713 views
Excel analysis assignment this is an independent assignment me von joney4
Excel analysis assignment this is an independent assignment meExcel analysis assignment this is an independent assignment me
Excel analysis assignment this is an independent assignment me
joney451 views
Oop lab assignment 01 von Drjilesh
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
Drjilesh41 views
A01 von lksoo
A01A01
A01
lksoo368 views
Data Structure.pdf von MemeMiner
Data Structure.pdfData Structure.pdf
Data Structure.pdf
MemeMiner12 views

Más de enidcruz

Lab7: More Arrays, Strings, Vectors, and Pointers von
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointersenidcruz
549 views4 Folien
Lab5: Functions 2 von
Lab5: Functions 2Lab5: Functions 2
Lab5: Functions 2enidcruz
339 views3 Folien
Lab4: Functions von
Lab4: FunctionsLab4: Functions
Lab4: Functionsenidcruz
566 views3 Folien
Lab3: More Flow of Control von
Lab3: More Flow of ControlLab3: More Flow of Control
Lab3: More Flow of Controlenidcruz
200 views2 Folien
Lab 1: Compiler Toolchain von
Lab 1: Compiler ToolchainLab 1: Compiler Toolchain
Lab 1: Compiler Toolchainenidcruz
194 views4 Folien
My First Source Code von
My First Source CodeMy First Source Code
My First Source Codeenidcruz
171 views1 Folie

Más de enidcruz(8)

Lab7: More Arrays, Strings, Vectors, and Pointers von enidcruz
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointers
enidcruz549 views
Lab5: Functions 2 von enidcruz
Lab5: Functions 2Lab5: Functions 2
Lab5: Functions 2
enidcruz339 views
Lab4: Functions von enidcruz
Lab4: FunctionsLab4: Functions
Lab4: Functions
enidcruz566 views
Lab3: More Flow of Control von enidcruz
Lab3: More Flow of ControlLab3: More Flow of Control
Lab3: More Flow of Control
enidcruz200 views
Lab 1: Compiler Toolchain von enidcruz
Lab 1: Compiler ToolchainLab 1: Compiler Toolchain
Lab 1: Compiler Toolchain
enidcruz194 views
My First Source Code von enidcruz
My First Source CodeMy First Source Code
My First Source Code
enidcruz171 views
Comp 3010 Syllabus von enidcruz
Comp 3010 SyllabusComp 3010 Syllabus
Comp 3010 Syllabus
enidcruz310 views
Foto-ensayo VIEQUES von enidcruz
Foto-ensayo VIEQUESFoto-ensayo VIEQUES
Foto-ensayo VIEQUES
enidcruz550 views

Último

Artificial Intelligence Helps in Drug Designing and Discovery.pptx von
Artificial Intelligence Helps in Drug Designing and Discovery.pptxArtificial Intelligence Helps in Drug Designing and Discovery.pptx
Artificial Intelligence Helps in Drug Designing and Discovery.pptxabhinashsahoo2001
117 views22 Folien
Metatheoretical Panda-Samaneh Borji.pdf von
Metatheoretical Panda-Samaneh Borji.pdfMetatheoretical Panda-Samaneh Borji.pdf
Metatheoretical Panda-Samaneh Borji.pdfsamanehborji
16 views29 Folien
Class 2 (12 july).pdf von
  Class 2 (12 july).pdf  Class 2 (12 july).pdf
Class 2 (12 july).pdfclimber9977
9 views1 Folie
1978 NASA News Release Log von
1978 NASA News Release Log1978 NASA News Release Log
1978 NASA News Release Logpurrterminator
7 views146 Folien
Conventional and non-conventional methods for improvement of cucurbits.pptx von
Conventional and non-conventional methods for improvement of cucurbits.pptxConventional and non-conventional methods for improvement of cucurbits.pptx
Conventional and non-conventional methods for improvement of cucurbits.pptxgandhi976
16 views35 Folien
Journal of Geographical Research | Vol.6, Iss.4 October 2023 von
Journal of Geographical Research | Vol.6, Iss.4 October 2023Journal of Geographical Research | Vol.6, Iss.4 October 2023
Journal of Geographical Research | Vol.6, Iss.4 October 2023Bilingual Publishing Group
11 views77 Folien

Último(20)

Artificial Intelligence Helps in Drug Designing and Discovery.pptx von abhinashsahoo2001
Artificial Intelligence Helps in Drug Designing and Discovery.pptxArtificial Intelligence Helps in Drug Designing and Discovery.pptx
Artificial Intelligence Helps in Drug Designing and Discovery.pptx
abhinashsahoo2001117 views
Metatheoretical Panda-Samaneh Borji.pdf von samanehborji
Metatheoretical Panda-Samaneh Borji.pdfMetatheoretical Panda-Samaneh Borji.pdf
Metatheoretical Panda-Samaneh Borji.pdf
samanehborji16 views
Conventional and non-conventional methods for improvement of cucurbits.pptx von gandhi976
Conventional and non-conventional methods for improvement of cucurbits.pptxConventional and non-conventional methods for improvement of cucurbits.pptx
Conventional and non-conventional methods for improvement of cucurbits.pptx
gandhi97616 views
Ethical issues associated with Genetically Modified Crops and Genetically Mod... von PunithKumars6
Ethical issues associated with Genetically Modified Crops and Genetically Mod...Ethical issues associated with Genetically Modified Crops and Genetically Mod...
Ethical issues associated with Genetically Modified Crops and Genetically Mod...
PunithKumars618 views
domestic waste_100013.pptx von padmasriv25
domestic waste_100013.pptxdomestic waste_100013.pptx
domestic waste_100013.pptx
padmasriv2511 views
Connecting communities to promote FAIR resources: perspectives from an RDA / ... von Allyson Lister
Connecting communities to promote FAIR resources: perspectives from an RDA / ...Connecting communities to promote FAIR resources: perspectives from an RDA / ...
Connecting communities to promote FAIR resources: perspectives from an RDA / ...
Allyson Lister33 views
Guinea Pig as a Model for Translation Research von PervaizDar1
Guinea Pig as a Model for Translation ResearchGuinea Pig as a Model for Translation Research
Guinea Pig as a Model for Translation Research
PervaizDar111 views
Workshop LLM Life Sciences ChemAI 231116.pptx von Marco Tibaldi
Workshop LLM Life Sciences ChemAI 231116.pptxWorkshop LLM Life Sciences ChemAI 231116.pptx
Workshop LLM Life Sciences ChemAI 231116.pptx
Marco Tibaldi101 views
application of genetic engineering 2.pptx von SankSurezz
application of genetic engineering 2.pptxapplication of genetic engineering 2.pptx
application of genetic engineering 2.pptx
SankSurezz6 views
MSC III_Advance Forensic Serology_Final.pptx von Suchita Rawat
MSC III_Advance Forensic Serology_Final.pptxMSC III_Advance Forensic Serology_Final.pptx
MSC III_Advance Forensic Serology_Final.pptx
Suchita Rawat10 views
Physical Characterization of Moon Impactor WE0913A von Sérgio Sacani
Physical Characterization of Moon Impactor WE0913APhysical Characterization of Moon Impactor WE0913A
Physical Characterization of Moon Impactor WE0913A
Sérgio Sacani42 views
CSF -SHEEBA.D presentation.pptx von SheebaD7
CSF -SHEEBA.D presentation.pptxCSF -SHEEBA.D presentation.pptx
CSF -SHEEBA.D presentation.pptx
SheebaD710 views
Matthias Beller ChemAI 231116.pptx von Marco Tibaldi
Matthias Beller ChemAI 231116.pptxMatthias Beller ChemAI 231116.pptx
Matthias Beller ChemAI 231116.pptx
Marco Tibaldi88 views

Lab6: I/O and Arrays

  • 1. Assigned: March 26, 2014 1 Due: April 13, 2014 HW 6: I/O and Arrays COMP 3010 Assigned on: March 26, 2014 Due on: April 13, 2014 Problem 1 (a) Compute the median of data file. The median is the number that has the same number of data elements greater than the numbers 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, or the average of the two middle elements if the file has an even 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. While testing construct several files on your own, including one with an even number of data points, increasing, and one with an odd number, also increasing. When you are confident your program is correct, modify it to read data from a file called dataMedianQuartiles (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 that takes its input from a file of numbers of type double. The program outputs to the screen the average and standard deviation of the numbers in the file. The file contains nothing but numbers of type double separated by blanks and/or line breaks. The standard deviation of a list of numbers n1, n2, n3, and so forth is defined as the square root of the average of the following numbers: (n1 − a)2 , (n2 − a)2 , (n3 − a)2 and so forth The number a is the average of the numbers n1, n2, n3, and so forth. Your program should read input from a file called stdDev. Hint: Write your program so that it first reads the entire file and computes the average of all the numbers, and then closes the file, then reopens the file and computes the standard deviation.
  • 2. HW 6: I/O and Arrays Assigned: March 26, 2014 2 Due: April 13, 2014 Problem 3 Write a program that merges the numbers in two files and writes all the numbers into a third file. Your program takes input from two different files and writes its output to a third file. Each input file contains a list of numbers of type int in sorted order from the smallest to the largest. After the program is run, the output file will contain all the numbers in the two input files in one longer list in sorted order from smallest to largest. Your program should define a function that is called with the two input-file streams and the output-file stream as three arguments. Your program needs to read input data from files merge1 and merge2 and write output to file merged. Problem 4 Hexadecimal numerals are integers written in base 16. The 16 digits used are ’0’ through ’9’ plus ’a’ for the “digit 10”, ’b’ for the “digit 11”, ’c’ for the “digit 12”, ’d’ for the “digit 13”, ’e’ for the “digit 14”, and ’f’ for the “digit 15”. For example, the hexadecimal numeral d is the same as base 10 numeral 13 and the hexadecimal numeral 1d is the same as the base 10 numeral 29. Write a C++ program to perform addition of two hexadecimal numerals each with up to 10 digits. if the result of the addition is more than 10 digits long, then simply give the output message “Addition Overflow” and not the result of the addition. Use arrays to store hexadecimal numerals as arrays of characters. Include a loop to repeat this calculation for new numbers until the user says she or he wants to end the program. Problem 5 Write a function called delete_repeats that has a partially filled array of characters as a formal parameter and that deletes all repeated letters from the array. Since a partially filled array requires two arguments, the function will actually have two formal parameters: an array parameter and a formal parameter of type int that gives the number of array positions used. When a letter is deleted, the remaining letters are moved forward to fill in the gap. This will create empty positions at the end of the array so that less of the array is used. Since the formal parameter is a partially filled array, a second formal parameter of type int will tell how many array positions are filled. This second formal parameter will be a call-by-reference parameter and will be changed to show how much of the array is used after the repeated letters are deleted. For example, consider the following code: char a[10]; a[0] = ’a’; a[l] = ’b’; a[2] = ’a’; a[3] = ’c’; int size = 4; delete_repeats(a, size);
  • 3. HW 6: I/O and Arrays Assigned: March 26, 2014 3 Due: April 13, 2014 After this code is executed, the value of a[0] is ’a’, the value of a[1] is ’b’, the value of a[2] is ’c’, and the value of size is 3. (The value of a[3] is no longer of any concern, since the partially filled array no longer uses this indexed variable.) You may assume that the partially filled array contains only lowercase letters. Embed your function in a suitable test program.