SlideShare a Scribd company logo
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.

More Related Content

What's hot

Fundamentals of Pointers in C
Fundamentals of Pointers in CFundamentals of Pointers in C
Fundamentals of Pointers in C
ShivanshuVerma11
 
Excel advanced formulas and functions i-school tutorials
Excel  advanced formulas and functions   i-school tutorialsExcel  advanced formulas and functions   i-school tutorials
Excel advanced formulas and functions i-school tutorials
techie_govind
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
tanmaymodi4
 
MS excel - match function
MS excel - match functionMS excel - match function
MS excel - match function
Vincent Segondo
 
User defined data type
User defined data typeUser defined data type
User defined data typeAmit Kapoor
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
Fahd Allebdi
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
MohammadSalman129
 
Spreadsheet formulas ppt (1)
Spreadsheet formulas ppt (1)Spreadsheet formulas ppt (1)
Spreadsheet formulas ppt (1)
Tammy Carter
 
Statistics 141 homework 6 complete solutions correct answers key
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 Love
 
Paper talk (presented by Prof. Ludaescher), WORKS workshop, 2010
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 Missier
 
Data Structures
Data StructuresData Structures
Data Structures
Nitesh Bichwani
 
Compiler design
Compiler designCompiler design
Compiler design
PriyadharshiniVS
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
DrSudeshna
 
data structures and algorithms Unit 1
data structures and algorithms Unit 1data structures and algorithms Unit 1
data structures and algorithms Unit 1
infanciaj
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
madan reddy
 
Informatica faq's
Informatica faq'sInformatica faq's
Informatica faq's
Rajasekhar Cherukuri
 
Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and Pointers
SimoniShah6
 

What's hot (19)

Fundamentals of Pointers in C
Fundamentals of Pointers in CFundamentals of Pointers in C
Fundamentals of Pointers in C
 
Excel advanced formulas and functions i-school tutorials
Excel  advanced formulas and functions   i-school tutorialsExcel  advanced formulas and functions   i-school tutorials
Excel advanced formulas and functions i-school tutorials
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
MS excel - match function
MS excel - match functionMS excel - match function
MS excel - match function
 
User defined data type
User defined data typeUser defined data type
User defined data type
 
Ch13
Ch13Ch13
Ch13
 
Functions
FunctionsFunctions
Functions
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
Spreadsheet formulas ppt (1)
Spreadsheet formulas ppt (1)Spreadsheet formulas ppt (1)
Spreadsheet formulas ppt (1)
 
Statistics 141 homework 6 complete solutions correct answers key
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
 
Paper talk (presented by Prof. Ludaescher), WORKS workshop, 2010
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
 
Data Structures
Data StructuresData Structures
Data Structures
 
Compiler design
Compiler designCompiler design
Compiler design
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
 
data structures and algorithms Unit 1
data structures and algorithms Unit 1data structures and algorithms Unit 1
data structures and algorithms Unit 1
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Informatica faq's
Informatica faq'sInformatica faq's
Informatica faq's
 
Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and Pointers
 

Similar to Lab6: I/O and Arrays

java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
Input-output
Input-outputInput-output
Input-output
neda marie maramo
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
adihartanto7
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
KabilaArun
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
DrGSakthiGovindaraju
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
attalurilalitha
 
CS10 Python Programming Homework 4 40 points Lists, Tupl.docx
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
mydrynan
 
Develop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdfDevelop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdf
leventhalbrad49439
 
Please help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdfPlease help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdf
fsenterprises
 
c++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptxc++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptx
JanineCallangan
 
paython practical
paython practical paython practical
paython practical
Upadhyayjanki
 
Project
ProjectProject
Mmt 001
Mmt 001Mmt 001
Mmt 001
sujatam8
 
Numerical data.
Numerical data.Numerical data.
Numerical data.
Adewumi Ezekiel Adebayo
 
C programming session 04
C programming session 04C programming session 04
C programming session 04Dushmanta Nath
 
C++
C++C++
Excel analysis assignment this is an independent assignment me
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
joney4
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
Drjilesh
 
A01
A01A01
A01
lksoo
 

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

java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
 
Input-output
Input-outputInput-output
Input-output
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
CS10 Python Programming Homework 4 40 points Lists, Tupl.docx
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
 
Develop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdfDevelop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdf
 
Hw5
Hw5Hw5
Hw5
 
Please help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdfPlease help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdf
 
c++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptxc++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptx
 
paython practical
paython practical paython practical
paython practical
 
Project
ProjectProject
Project
 
Mmt 001
Mmt 001Mmt 001
Mmt 001
 
Numerical data.
Numerical data.Numerical data.
Numerical data.
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
C++
C++C++
C++
 
Excel analysis assignment this is an independent assignment me
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
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
 
A01
A01A01
A01
 

More from enidcruz

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

More from enidcruz (8)

Lab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointers
 
Lab5: Functions 2
Lab5: Functions 2Lab5: Functions 2
Lab5: Functions 2
 
Lab4: Functions
Lab4: FunctionsLab4: Functions
Lab4: Functions
 
Lab3: More Flow of Control
Lab3: More Flow of ControlLab3: More Flow of Control
Lab3: More Flow of Control
 
Lab 1: Compiler Toolchain
Lab 1: Compiler ToolchainLab 1: Compiler Toolchain
Lab 1: Compiler Toolchain
 
My First Source Code
My First Source CodeMy First Source Code
My First Source Code
 
Comp 3010 Syllabus
Comp 3010 SyllabusComp 3010 Syllabus
Comp 3010 Syllabus
 
Foto-ensayo VIEQUES
Foto-ensayo VIEQUESFoto-ensayo VIEQUES
Foto-ensayo VIEQUES
 

Recently uploaded

Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Ana Luísa Pinho
 
Richard's entangled aventures in wonderland
Richard's entangled aventures in wonderlandRichard's entangled aventures in wonderland
Richard's entangled aventures in wonderland
Richard Gill
 
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
NathanBaughman3
 
SCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SCHIZOPHRENIA Disorder/ Brain Disorder.pdfSCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SELF-EXPLANATORY
 
Hemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptxHemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptx
muralinath2
 
role of pramana in research.pptx in science
role of pramana in research.pptx in sciencerole of pramana in research.pptx in science
role of pramana in research.pptx in science
sonaliswain16
 
Nucleic Acid-its structural and functional complexity.
Nucleic Acid-its structural and functional complexity.Nucleic Acid-its structural and functional complexity.
Nucleic Acid-its structural and functional complexity.
Nistarini College, Purulia (W.B) India
 
Mammalian Pineal Body Structure and Also Functions
Mammalian Pineal Body Structure and Also FunctionsMammalian Pineal Body Structure and Also Functions
Mammalian Pineal Body Structure and Also Functions
YOGESH DOGRA
 
insect taxonomy importance systematics and classification
insect taxonomy importance systematics and classificationinsect taxonomy importance systematics and classification
insect taxonomy importance systematics and classification
anitaento25
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
Sérgio Sacani
 
ESR_factors_affect-clinic significance-Pathysiology.pptx
ESR_factors_affect-clinic significance-Pathysiology.pptxESR_factors_affect-clinic significance-Pathysiology.pptx
ESR_factors_affect-clinic significance-Pathysiology.pptx
muralinath2
 
Citrus Greening Disease and its Management
Citrus Greening Disease and its ManagementCitrus Greening Disease and its Management
Citrus Greening Disease and its Management
subedisuryaofficial
 
general properties of oerganologametal.ppt
general properties of oerganologametal.pptgeneral properties of oerganologametal.ppt
general properties of oerganologametal.ppt
IqrimaNabilatulhusni
 
4. An Overview of Sugarcane White Leaf Disease in Vietnam.pdf
4. An Overview of Sugarcane White Leaf Disease in Vietnam.pdf4. An Overview of Sugarcane White Leaf Disease in Vietnam.pdf
4. An Overview of Sugarcane White Leaf Disease in Vietnam.pdf
ssuserbfdca9
 
Hemoglobin metabolism_pathophysiology.pptx
Hemoglobin metabolism_pathophysiology.pptxHemoglobin metabolism_pathophysiology.pptx
Hemoglobin metabolism_pathophysiology.pptx
muralinath2
 
Cancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate PathwayCancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate Pathway
AADYARAJPANDEY1
 
Lateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensiveLateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensive
silvermistyshot
 
Circulatory system_ Laplace law. Ohms law.reynaults law,baro-chemo-receptors-...
Circulatory system_ Laplace law. Ohms law.reynaults law,baro-chemo-receptors-...Circulatory system_ Laplace law. Ohms law.reynaults law,baro-chemo-receptors-...
Circulatory system_ Laplace law. Ohms law.reynaults law,baro-chemo-receptors-...
muralinath2
 
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
University of Maribor
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Sérgio Sacani
 

Recently uploaded (20)

Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
 
Richard's entangled aventures in wonderland
Richard's entangled aventures in wonderlandRichard's entangled aventures in wonderland
Richard's entangled aventures in wonderland
 
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
 
SCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SCHIZOPHRENIA Disorder/ Brain Disorder.pdfSCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SCHIZOPHRENIA Disorder/ Brain Disorder.pdf
 
Hemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptxHemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptx
 
role of pramana in research.pptx in science
role of pramana in research.pptx in sciencerole of pramana in research.pptx in science
role of pramana in research.pptx in science
 
Nucleic Acid-its structural and functional complexity.
Nucleic Acid-its structural and functional complexity.Nucleic Acid-its structural and functional complexity.
Nucleic Acid-its structural and functional complexity.
 
Mammalian Pineal Body Structure and Also Functions
Mammalian Pineal Body Structure and Also FunctionsMammalian Pineal Body Structure and Also Functions
Mammalian Pineal Body Structure and Also Functions
 
insect taxonomy importance systematics and classification
insect taxonomy importance systematics and classificationinsect taxonomy importance systematics and classification
insect taxonomy importance systematics and classification
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
 
ESR_factors_affect-clinic significance-Pathysiology.pptx
ESR_factors_affect-clinic significance-Pathysiology.pptxESR_factors_affect-clinic significance-Pathysiology.pptx
ESR_factors_affect-clinic significance-Pathysiology.pptx
 
Citrus Greening Disease and its Management
Citrus Greening Disease and its ManagementCitrus Greening Disease and its Management
Citrus Greening Disease and its Management
 
general properties of oerganologametal.ppt
general properties of oerganologametal.pptgeneral properties of oerganologametal.ppt
general properties of oerganologametal.ppt
 
4. An Overview of Sugarcane White Leaf Disease in Vietnam.pdf
4. An Overview of Sugarcane White Leaf Disease in Vietnam.pdf4. An Overview of Sugarcane White Leaf Disease in Vietnam.pdf
4. An Overview of Sugarcane White Leaf Disease in Vietnam.pdf
 
Hemoglobin metabolism_pathophysiology.pptx
Hemoglobin metabolism_pathophysiology.pptxHemoglobin metabolism_pathophysiology.pptx
Hemoglobin metabolism_pathophysiology.pptx
 
Cancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate PathwayCancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate Pathway
 
Lateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensiveLateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensive
 
Circulatory system_ Laplace law. Ohms law.reynaults law,baro-chemo-receptors-...
Circulatory system_ Laplace law. Ohms law.reynaults law,baro-chemo-receptors-...Circulatory system_ Laplace law. Ohms law.reynaults law,baro-chemo-receptors-...
Circulatory system_ Laplace law. Ohms law.reynaults law,baro-chemo-receptors-...
 
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
 

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.