SlideShare una empresa de Scribd logo
1 de 6
Descargar para leer sin conexión
Update
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
class Control {
private:
int arr[1000];
int size = 1000;
public:
Control() {
srand(time(NULL));
ifstream file("numbers.txt");
if (file.is_open()) {
for (int i = 0; i < size; i++) {
file >> arr[i];
}
file.close();
}
else {
cout << "Unable to open file." << endl;
}
for (int i = 0; i < size; i++) {
arr[i] = rand() % 1000 + 1;
}
}
void outputAll() {
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
void outputSum() {
int sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
}
cout << "Sum: " << sum << endl;
}
void outputOdd() {
cout << "Odd numbers: ";
for (int i = 0; i < size; i++) {
if (arr[i] % 2 != 0) {
cout << arr[i] << " ";
}
}
cout << endl;
}
void outputEven() {
cout << "Even numbers: ";
for (int i = 0; i < size; i++) {
if (arr[i] % 2 == 0) {
cout << arr[i] << " ";
}
}
cout << endl;
}
void linearSearch(int val) {
bool found = false;
for (int i = 0; i < size; i++) {
if (arr[i] == val) {
found = true;
cout << "Value found at index " << i << endl;
break;
}
}
if (!found) {
cout << "Value not found." << endl;
}
}
void outputMiddle() {
int middle = size / 2;
cout << "Middle value(s): ";
if (size % 2 == 0) {
cout << arr[middle - 1] << " " << arr[middle] << endl;
}
else {
cout << arr[middle] << endl;
}
}
void outputFirst() {
cout << "First value: " << arr[0] << endl;
}
void outputLast() {
cout << "Last value: " << arr[size - 1] << endl;
}
void outputHighest() {
int highest = arr[0];
int index = 0;
for (int i = 1; i < size; i++) {
if (arr[i] > highest) {
highest = arr[i];
index = i;
}
}
cout << "Highest value: " << highest << " (index " << index << ")" << endl;
}
void outputLowest() {
int lowest = arr[0];
int index = 0;
for (int i = 1; i < size; i++) {
if (arr[i] < lowest) {
lowest = arr[i];
index = i;
}
}
cout << "Lowest value: " << lowest << " (index " << index << ")" << endl;
}
void bubbleSort() {
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
cout << "Array sorted in ascending order using bubble sort." << endl;
}
};
int main(){
Control c;
c.outputAll();
c.outputSum();
c.outputOdd();
c.outputEven();
c.outputFirst();
c.outputLast();
c.outputMiddle();
c.linearSearch();
c.outputLowest();
c.outputHighest();
}
Create a conventional structure for C++ Program
Header File (Outline / Framework of C++ Class File)
Driver File (File Containing Main Function)
Class Implementation File
Make Sure all the files are organized in the same directory.
Main Function: Control of operation
Common_Alg
The array will be a Class Variable {Implement Dynamic array)
In your Class declare and fill an array with 1000 random integers between 1 - 1000 from your .txt
file used in previous tasks.
Filling the array with random integers should happen in the class constructor.
***Hint: use the class constructor.
The algorithm outputs below should remain the same.
Implement Binary Search algorithm instead of Linear Search Algorithm
Directory Holding Header File / Driver File / Class Implementation File:
Attach Snipping Photo of Command Line Navigation and Files in the Directory
Main Function:
Attach a snipping photo of source code
Class Constructor:
Attach a snipping photo of source code
Method 1: Output all values
Attach a snipping photo of source code and output
Method 2: Output sum All values
Attach a snipping photo of source code and output
Method 3: Output All odd numbers
Attach a snipping photo of source code and output
Method 4: Output All Even numbers
Attach a snipping photo of source code and output
Method 5: Enter a search value /Binary Search
New
Attach a snipping photo of source code and output
Method 6: Output Middle Value (Values in the Middle)
Not Average
New
Attach a snipping photo of source code and output
Method 7: Output First Value in the Array
New
Attach a snipping photo of source code and output
Method 8: Output Last Value in the Array
New
Attach a snipping photo of source code and output
Method 9: Output the Highest Value and its location in the array. (Hardcode the algorithm.)
New
Attach a snipping photo of the source code and output
Method 10: Output the Lowest Value and its location in the array. (Hardcode the algorithm.)
New
Attach a snipping photo of source code and output
Method 11:
Bubble Sort
New
Attach a snipping photo of source code and output
Directory Holding Header File / Driver File / Class Implementation File:
Attach Snipping Photo of Command Line Navigation and Files in the Directory
Main Function:
Attach a snipping photo of source code
Class Constructor:
Attach a snipping photo of source code
Method 1: Output all values
Attach a snipping photo of source code and output
Method 2: Output sum All values
Attach a snipping photo of source code and output
Method 3: Output All odd numbers
Attach a snipping photo of source code and output
Method 4: Output All Even numbers
Attach a snipping photo of source code and output
Method 5: Enter a search value /Binary Search
New
Attach a snipping photo of source code and output
Method 6: Output Middle Value (Values in the Middle)
Not Average
New
Attach a snipping photo of source code and output
Method 7: Output First Value in the Array
New
Attach a snipping photo of source code and output
Method 8: Output Last Value in the Array
New
Attach a snipping photo of source code and output
Method 9: Output the Highest Value and its location in the array. (Hardcode the algorithm.)
New
Attach a snipping photo of the source code and output
Method 10: Output the Lowest Value and its location in the array. (Hardcode the algorithm.)
New
Attach a snipping photo of source code and output
Method 11:
Bubble Sort
New
Attach a snipping photo of source code and output

Más contenido relacionado

Similar a Update include ltiostreamgt include ltfstreamgt .pdf

Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd StudyChris Ohk
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQLvikram mahendra
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxbraycarissa250
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorJussi Pohjolainen
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88Mahmoud Samir Fayed
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxJumanneChiyanda
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 
OOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxOOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxSirRafiLectures
 
Please follow the code and comments for description a)CODE #.pdf
Please follow the code and comments for description a)CODE #.pdfPlease follow the code and comments for description a)CODE #.pdf
Please follow the code and comments for description a)CODE #.pdfannaindustries
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 

Similar a Update include ltiostreamgt include ltfstreamgt .pdf (20)

Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
 
Computer Practical XII
Computer Practical XIIComputer Practical XII
Computer Practical XII
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
C++ practical
C++ practicalC++ practical
C++ practical
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Java practical
Java practicalJava practical
Java practical
 
OOPS 22-23 (1).pptx
OOPS 22-23 (1).pptxOOPS 22-23 (1).pptx
OOPS 22-23 (1).pptx
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptx
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
OOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxOOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptx
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
Please follow the code and comments for description a)CODE #.pdf
Please follow the code and comments for description a)CODE #.pdfPlease follow the code and comments for description a)CODE #.pdf
Please follow the code and comments for description a)CODE #.pdf
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 

Más de adityacommunications2

US Civilian Labor Force Participation Rate Civlian Unemplo.pdf
US Civilian Labor Force Participation Rate Civlian Unemplo.pdfUS Civilian Labor Force Participation Rate Civlian Unemplo.pdf
US Civilian Labor Force Participation Rate Civlian Unemplo.pdfadityacommunications2
 
US set to lift covid19 testing requirements for travelers f.pdf
US set to lift covid19 testing requirements for travelers f.pdfUS set to lift covid19 testing requirements for travelers f.pdf
US set to lift covid19 testing requirements for travelers f.pdfadityacommunications2
 
URINARY SYSTEMI Nephron COLORING EXERCISE part it Draw a.pdf
URINARY SYSTEMI Nephron COLORING EXERCISE part it  Draw a.pdfURINARY SYSTEMI Nephron COLORING EXERCISE part it  Draw a.pdf
URINARY SYSTEMI Nephron COLORING EXERCISE part it Draw a.pdfadityacommunications2
 
US Civilian Labor Force Participation Rate Cilitian Unempl.pdf
US Civilian Labor Force Participation Rate Cilitian Unempl.pdfUS Civilian Labor Force Participation Rate Cilitian Unempl.pdf
US Civilian Labor Force Participation Rate Cilitian Unempl.pdfadityacommunications2
 
US Civilian Labor Force Participation Rate Cillian Unemplo.pdf
US Civilian Labor Force Participation Rate Cillian Unemplo.pdfUS Civilian Labor Force Participation Rate Cillian Unemplo.pdf
US Civilian Labor Force Participation Rate Cillian Unemplo.pdfadityacommunications2
 
Urgent Draw the EER diagram for the Hiking Database given .pdf
Urgent  Draw the EER diagram for the Hiking Database given .pdfUrgent  Draw the EER diagram for the Hiking Database given .pdf
Urgent Draw the EER diagram for the Hiking Database given .pdfadityacommunications2
 
Upan denetic analysis ot the canceromis tissue a mutated fo.pdf
Upan denetic analysis ot the canceromis tissue a mutated fo.pdfUpan denetic analysis ot the canceromis tissue a mutated fo.pdf
Upan denetic analysis ot the canceromis tissue a mutated fo.pdfadityacommunications2
 
UPS prides itself on having uptodate information on the pr.pdf
UPS prides itself on having uptodate information on the pr.pdfUPS prides itself on having uptodate information on the pr.pdf
UPS prides itself on having uptodate information on the pr.pdfadityacommunications2
 
Underground Sandwiches a sandwich shop has the following m.pdf
Underground Sandwiches a sandwich shop has the following m.pdfUnderground Sandwiches a sandwich shop has the following m.pdf
Underground Sandwiches a sandwich shop has the following m.pdfadityacommunications2
 
Update the Assignment 3 code to follow the guidelines below .pdf
Update the Assignment 3 code to follow the guidelines below .pdfUpdate the Assignment 3 code to follow the guidelines below .pdf
Update the Assignment 3 code to follow the guidelines below .pdfadityacommunications2
 
Understand processivity and fidelity Indicate if a given enz.pdf
Understand processivity and fidelity Indicate if a given enz.pdfUnderstand processivity and fidelity Indicate if a given enz.pdf
Understand processivity and fidelity Indicate if a given enz.pdfadityacommunications2
 
Unlike the theory of international trade or the theory of in.pdf
Unlike the theory of international trade or the theory of in.pdfUnlike the theory of international trade or the theory of in.pdf
Unlike the theory of international trade or the theory of in.pdfadityacommunications2
 
Unemployment which is when persons in an economy have lost.pdf
Unemployment  which is when persons in an economy have lost.pdfUnemployment  which is when persons in an economy have lost.pdf
Unemployment which is when persons in an economy have lost.pdfadityacommunications2
 
Unknown case study2 Your patient is a 26 yo male who presen.pdf
Unknown case study2 Your patient is a 26 yo male who presen.pdfUnknown case study2 Your patient is a 26 yo male who presen.pdf
Unknown case study2 Your patient is a 26 yo male who presen.pdfadityacommunications2
 
Una moneda justa se lanza seis veces Cul es la probabilid.pdf
Una moneda justa se lanza seis veces Cul es la probabilid.pdfUna moneda justa se lanza seis veces Cul es la probabilid.pdf
Una moneda justa se lanza seis veces Cul es la probabilid.pdfadityacommunications2
 
Una persona con diabetes T2 debe tratar de controlar los car.pdf
Una persona con diabetes T2 debe tratar de controlar los car.pdfUna persona con diabetes T2 debe tratar de controlar los car.pdf
Una persona con diabetes T2 debe tratar de controlar los car.pdfadityacommunications2
 
Una forma principal en la que los genes tienen un efecto sob.pdf
Una forma principal en la que los genes tienen un efecto sob.pdfUna forma principal en la que los genes tienen un efecto sob.pdf
Una forma principal en la que los genes tienen un efecto sob.pdfadityacommunications2
 
Una fuerte correlacin entre A y B implicara que B es causa.pdf
Una fuerte correlacin entre A y B implicara que B es causa.pdfUna fuerte correlacin entre A y B implicara que B es causa.pdf
Una fuerte correlacin entre A y B implicara que B es causa.pdfadityacommunications2
 
Unit 11 Forum 6 6 unread replies 6 6 replies Find a video .pdf
Unit 11 Forum 6 6 unread replies 6 6 replies Find a video .pdfUnit 11 Forum 6 6 unread replies 6 6 replies Find a video .pdf
Unit 11 Forum 6 6 unread replies 6 6 replies Find a video .pdfadityacommunications2
 
Una enfermera est cuidando a un cliente adulto mayor La e.pdf
Una enfermera est cuidando a un cliente adulto mayor La e.pdfUna enfermera est cuidando a un cliente adulto mayor La e.pdf
Una enfermera est cuidando a un cliente adulto mayor La e.pdfadityacommunications2
 

Más de adityacommunications2 (20)

US Civilian Labor Force Participation Rate Civlian Unemplo.pdf
US Civilian Labor Force Participation Rate Civlian Unemplo.pdfUS Civilian Labor Force Participation Rate Civlian Unemplo.pdf
US Civilian Labor Force Participation Rate Civlian Unemplo.pdf
 
US set to lift covid19 testing requirements for travelers f.pdf
US set to lift covid19 testing requirements for travelers f.pdfUS set to lift covid19 testing requirements for travelers f.pdf
US set to lift covid19 testing requirements for travelers f.pdf
 
URINARY SYSTEMI Nephron COLORING EXERCISE part it Draw a.pdf
URINARY SYSTEMI Nephron COLORING EXERCISE part it  Draw a.pdfURINARY SYSTEMI Nephron COLORING EXERCISE part it  Draw a.pdf
URINARY SYSTEMI Nephron COLORING EXERCISE part it Draw a.pdf
 
US Civilian Labor Force Participation Rate Cilitian Unempl.pdf
US Civilian Labor Force Participation Rate Cilitian Unempl.pdfUS Civilian Labor Force Participation Rate Cilitian Unempl.pdf
US Civilian Labor Force Participation Rate Cilitian Unempl.pdf
 
US Civilian Labor Force Participation Rate Cillian Unemplo.pdf
US Civilian Labor Force Participation Rate Cillian Unemplo.pdfUS Civilian Labor Force Participation Rate Cillian Unemplo.pdf
US Civilian Labor Force Participation Rate Cillian Unemplo.pdf
 
Urgent Draw the EER diagram for the Hiking Database given .pdf
Urgent  Draw the EER diagram for the Hiking Database given .pdfUrgent  Draw the EER diagram for the Hiking Database given .pdf
Urgent Draw the EER diagram for the Hiking Database given .pdf
 
Upan denetic analysis ot the canceromis tissue a mutated fo.pdf
Upan denetic analysis ot the canceromis tissue a mutated fo.pdfUpan denetic analysis ot the canceromis tissue a mutated fo.pdf
Upan denetic analysis ot the canceromis tissue a mutated fo.pdf
 
UPS prides itself on having uptodate information on the pr.pdf
UPS prides itself on having uptodate information on the pr.pdfUPS prides itself on having uptodate information on the pr.pdf
UPS prides itself on having uptodate information on the pr.pdf
 
Underground Sandwiches a sandwich shop has the following m.pdf
Underground Sandwiches a sandwich shop has the following m.pdfUnderground Sandwiches a sandwich shop has the following m.pdf
Underground Sandwiches a sandwich shop has the following m.pdf
 
Update the Assignment 3 code to follow the guidelines below .pdf
Update the Assignment 3 code to follow the guidelines below .pdfUpdate the Assignment 3 code to follow the guidelines below .pdf
Update the Assignment 3 code to follow the guidelines below .pdf
 
Understand processivity and fidelity Indicate if a given enz.pdf
Understand processivity and fidelity Indicate if a given enz.pdfUnderstand processivity and fidelity Indicate if a given enz.pdf
Understand processivity and fidelity Indicate if a given enz.pdf
 
Unlike the theory of international trade or the theory of in.pdf
Unlike the theory of international trade or the theory of in.pdfUnlike the theory of international trade or the theory of in.pdf
Unlike the theory of international trade or the theory of in.pdf
 
Unemployment which is when persons in an economy have lost.pdf
Unemployment  which is when persons in an economy have lost.pdfUnemployment  which is when persons in an economy have lost.pdf
Unemployment which is when persons in an economy have lost.pdf
 
Unknown case study2 Your patient is a 26 yo male who presen.pdf
Unknown case study2 Your patient is a 26 yo male who presen.pdfUnknown case study2 Your patient is a 26 yo male who presen.pdf
Unknown case study2 Your patient is a 26 yo male who presen.pdf
 
Una moneda justa se lanza seis veces Cul es la probabilid.pdf
Una moneda justa se lanza seis veces Cul es la probabilid.pdfUna moneda justa se lanza seis veces Cul es la probabilid.pdf
Una moneda justa se lanza seis veces Cul es la probabilid.pdf
 
Una persona con diabetes T2 debe tratar de controlar los car.pdf
Una persona con diabetes T2 debe tratar de controlar los car.pdfUna persona con diabetes T2 debe tratar de controlar los car.pdf
Una persona con diabetes T2 debe tratar de controlar los car.pdf
 
Una forma principal en la que los genes tienen un efecto sob.pdf
Una forma principal en la que los genes tienen un efecto sob.pdfUna forma principal en la que los genes tienen un efecto sob.pdf
Una forma principal en la que los genes tienen un efecto sob.pdf
 
Una fuerte correlacin entre A y B implicara que B es causa.pdf
Una fuerte correlacin entre A y B implicara que B es causa.pdfUna fuerte correlacin entre A y B implicara que B es causa.pdf
Una fuerte correlacin entre A y B implicara que B es causa.pdf
 
Unit 11 Forum 6 6 unread replies 6 6 replies Find a video .pdf
Unit 11 Forum 6 6 unread replies 6 6 replies Find a video .pdfUnit 11 Forum 6 6 unread replies 6 6 replies Find a video .pdf
Unit 11 Forum 6 6 unread replies 6 6 replies Find a video .pdf
 
Una enfermera est cuidando a un cliente adulto mayor La e.pdf
Una enfermera est cuidando a un cliente adulto mayor La e.pdfUna enfermera est cuidando a un cliente adulto mayor La e.pdf
Una enfermera est cuidando a un cliente adulto mayor La e.pdf
 

Último

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

Update include ltiostreamgt include ltfstreamgt .pdf

  • 1. Update #include <iostream> #include <fstream> #include <cstdlib> #include <ctime> using namespace std; class Control { private: int arr[1000]; int size = 1000; public: Control() { srand(time(NULL)); ifstream file("numbers.txt"); if (file.is_open()) { for (int i = 0; i < size; i++) { file >> arr[i]; } file.close(); } else { cout << "Unable to open file." << endl; } for (int i = 0; i < size; i++) { arr[i] = rand() % 1000 + 1; } } void outputAll() { for (int i = 0; i < size; i++) { cout << arr[i] << " "; } cout << endl; } void outputSum() { int sum = 0; for (int i = 0; i < size; i++) { sum += arr[i]; } cout << "Sum: " << sum << endl; } void outputOdd() { cout << "Odd numbers: ";
  • 2. for (int i = 0; i < size; i++) { if (arr[i] % 2 != 0) { cout << arr[i] << " "; } } cout << endl; } void outputEven() { cout << "Even numbers: "; for (int i = 0; i < size; i++) { if (arr[i] % 2 == 0) { cout << arr[i] << " "; } } cout << endl; } void linearSearch(int val) { bool found = false; for (int i = 0; i < size; i++) { if (arr[i] == val) { found = true; cout << "Value found at index " << i << endl; break; } } if (!found) { cout << "Value not found." << endl; } } void outputMiddle() { int middle = size / 2; cout << "Middle value(s): "; if (size % 2 == 0) { cout << arr[middle - 1] << " " << arr[middle] << endl; } else { cout << arr[middle] << endl; } } void outputFirst() { cout << "First value: " << arr[0] << endl; }
  • 3. void outputLast() { cout << "Last value: " << arr[size - 1] << endl; } void outputHighest() { int highest = arr[0]; int index = 0; for (int i = 1; i < size; i++) { if (arr[i] > highest) { highest = arr[i]; index = i; } } cout << "Highest value: " << highest << " (index " << index << ")" << endl; } void outputLowest() { int lowest = arr[0]; int index = 0; for (int i = 1; i < size; i++) { if (arr[i] < lowest) { lowest = arr[i]; index = i; } } cout << "Lowest value: " << lowest << " (index " << index << ")" << endl; } void bubbleSort() { for (int i = 0; i < size - 1; i++) { for (int j = 0; j < size - i - 1; j++) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } cout << "Array sorted in ascending order using bubble sort." << endl; } }; int main(){ Control c; c.outputAll(); c.outputSum();
  • 4. c.outputOdd(); c.outputEven(); c.outputFirst(); c.outputLast(); c.outputMiddle(); c.linearSearch(); c.outputLowest(); c.outputHighest(); } Create a conventional structure for C++ Program Header File (Outline / Framework of C++ Class File) Driver File (File Containing Main Function) Class Implementation File Make Sure all the files are organized in the same directory. Main Function: Control of operation Common_Alg The array will be a Class Variable {Implement Dynamic array) In your Class declare and fill an array with 1000 random integers between 1 - 1000 from your .txt file used in previous tasks. Filling the array with random integers should happen in the class constructor. ***Hint: use the class constructor. The algorithm outputs below should remain the same. Implement Binary Search algorithm instead of Linear Search Algorithm Directory Holding Header File / Driver File / Class Implementation File: Attach Snipping Photo of Command Line Navigation and Files in the Directory Main Function: Attach a snipping photo of source code Class Constructor: Attach a snipping photo of source code Method 1: Output all values Attach a snipping photo of source code and output Method 2: Output sum All values Attach a snipping photo of source code and output Method 3: Output All odd numbers Attach a snipping photo of source code and output Method 4: Output All Even numbers Attach a snipping photo of source code and output Method 5: Enter a search value /Binary Search New Attach a snipping photo of source code and output Method 6: Output Middle Value (Values in the Middle) Not Average
  • 5. New Attach a snipping photo of source code and output Method 7: Output First Value in the Array New Attach a snipping photo of source code and output Method 8: Output Last Value in the Array New Attach a snipping photo of source code and output Method 9: Output the Highest Value and its location in the array. (Hardcode the algorithm.) New Attach a snipping photo of the source code and output Method 10: Output the Lowest Value and its location in the array. (Hardcode the algorithm.) New Attach a snipping photo of source code and output Method 11: Bubble Sort New Attach a snipping photo of source code and output Directory Holding Header File / Driver File / Class Implementation File: Attach Snipping Photo of Command Line Navigation and Files in the Directory Main Function: Attach a snipping photo of source code Class Constructor: Attach a snipping photo of source code Method 1: Output all values Attach a snipping photo of source code and output Method 2: Output sum All values Attach a snipping photo of source code and output Method 3: Output All odd numbers Attach a snipping photo of source code and output Method 4: Output All Even numbers Attach a snipping photo of source code and output Method 5: Enter a search value /Binary Search New Attach a snipping photo of source code and output Method 6: Output Middle Value (Values in the Middle) Not Average New Attach a snipping photo of source code and output
  • 6. Method 7: Output First Value in the Array New Attach a snipping photo of source code and output Method 8: Output Last Value in the Array New Attach a snipping photo of source code and output Method 9: Output the Highest Value and its location in the array. (Hardcode the algorithm.) New Attach a snipping photo of the source code and output Method 10: Output the Lowest Value and its location in the array. (Hardcode the algorithm.) New Attach a snipping photo of source code and output Method 11: Bubble Sort New Attach a snipping photo of source code and output