Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given an array, A, that contains datasize number of values: Write C++ code segme

ID: 3680495 • Letter: G

Question

Given an array, A, that contains datasize number of values:
Write C++ code segments to do each of the following:
1. Search the array for a particular value. Assign a boolean value with true if the search value is found in the array, and false if the value is not found. Write out a ‘found’ message if the boolean value is true and a ‘not found’ message if not.
2. Search the array for a particular value. Assign an integer with the value of -1 if the search value is not found in the array, and the array subscript where it was found if the value is present in the array. Write out the search value and the location in which it was found if it was found, and a ‘not found’ message if not.
3. Open an input file named “input.txt”. Ask the user for the name of an output file and open that file for output. Read in 3 values from the input file and write them out to the output file.
4. Declare a struct type named Employee that contains: name: a string hourlyWage: a double hoursPerDay: an array of 7 integers Give main program statements that would declare one struct variable and read values into all elements from the keyboard.

Explanation / Answer

Please find the code below :

1)

int get_size(int arr[]) {
return sizeof(arr);
}

void search(int val, int * arr){

bool found = false;
for(int i=0; i<get_size(arr); i++){
if(arr[i]==val){
found = true;
break;
}
}

if(found)
cout << "found" << endl;
else
cout << "not found" << endl;

}

2)


int get_size(int arr[]) {
return sizeof(arr);
}

void search(int val, int * arr){

int foundAt = -1;
for(int i=0; i<get_size(arr); i++){
if(arr[i]==val){
foundAt = i;
break;
}
}

if(foundAt!=-1)
cout << val << " found at position: "<< foundAt << endl;
else
cout << "not found" << endl;

}

3)

#include <iostream>
#include <fstream>
#include <string>
using namespace std;


int main () {
string line;
ifstream myfileRead ("input.txt");
if (myfileRead.is_open())
{
string fname;
cout << "Enter output name:" << endl;
ofstream myfile (fname);
if (myfile.is_open())
{
int i=1;
while ( getline (myfileRead,line) && i<=3)
{
myfile << line << ' ';
i++;
}
myfile.close();
} else
cout << "Unable to open file";
myfileRead.close();
}

else cout << "Unable to open file";

return 0;
}

4)

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct Employee{
string name;
string hourlyWage;
double hoursPerDay[];
};

int main () {

Employee emp;
cout << "Enter employee name" << endl;
cin >> emp.name;
cout << "Enter employee hourlyWage" << endl;
cin >> emp.hourlyWage;
cout << "Enter employee 7 values for hoursPerDay" << endl;
  
for(int i=0; i<7; i++){
cin >> emp.hoursPerDay[i];   
}
  
  
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote