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

Hello, experts. I ned your help finishing this in C++: -------------------------

ID: 3679963 • Letter: H

Question

Hello, experts. I ned your help finishing this in C++:

------------------------------------------------------------------------------------

A. Write a linear search function that accepts a string array, a string search argument and the number of elements in the array. The function will return -1 if the string is not found and the position of the string if it is found. Test this function before attempting to use it in the next program

int strsearch (string list[ ], string argument, int ne) is the function header

=======================================

B. Write a program that uses the data in the MDLotteryData.txt file. The program should read a date from the user (string in m/d/y format as above) and return a winning number according to the user’s choice. The program will ask the user to input:

            1 to see the 3 digit MidDay number for the date given

            2 to see the 3 digit Evening number for the date given

            3 to see the 4 digit MidDay number for the date given

            4 to see the 4 digit Evening number for the date given

            5 to see all four numbers for the date given

The program will then return the numbers desired by the user, ask the user if she/he wants to enter another date and continue or stop. Arrays used in the algorithm below: dates[426 ] and numbers[ 426][4] (or whatever storage arrangement you have chosen, but you will then change the algorithm appropriately)

read data from MDLotteryData.txt into dates and numbers

      response = “yes”

      while (response is the same as “yes”)

     read date (from user)

     do   (read and validate choice)

         read choice (from user)

      while (choice NOT between 1 and 5)

      end loop

     search dates to find date (using linear search function, that you will write)

            pos = search(dates,date,426)    or something similar

     if pos is the same as -1 tell the user that the date cannot be found

     else

     If If choice is 5

                 for k= 0 to 3

                 print numbers [pos] [k]

         else

                 print numbers [pos] [choice-1]

         endif

     endif

     print “ do again?”

     read response

endloop

=======================================

C. Write a program which reads only the 3 digit and 4 digit numbers from the file (ignoring the date and mid vs evening as well) into two arrays: threeDigit[852] and fourDigit[852] ( alternately you might want to consider using a 2-dimensional array)

Sort each array using either bubble or selection sort.

The user will enter three digits or a 4 digit number and a code indicating which type he has entered and the program will look for that number in one of the two arrays, using the binary search method.

      The program will tell the user whether or not the number has appeared.

((( Submit: source code and sample output for B and C. )))

=============================

MDLotteryData is upload it in thus link: https://www.scribd.com/doc/305453286/Md-Lottery-Data

Explanation / Answer

Linear search function-

int linsearch(string val)

{

for (int j=0; j <= 3; j++)

{

    if (player[j].getLastName()==val)

     return j ;        

}

    return -1 ;

}

void showinfo()

{

string search;

int found ;

cout << "Please Enter The Player's Last Name : " ;

cin >> search ;

found=linsearch(search);

if (found == -1)

{

    cout << " There is no player called " << search ;

}

Reading from a file

// reading a text file

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main () {

string line;

ifstream myfile ("example.txt");

if (myfile.is_open())

{

    while ( getline (myfile,line) )

    {

      cout << line << ' ';

    }

    myfile.close();

}

else cout << "Unable to open file";

return 0;

}

Sample Code to read date and display the result

#include<iostream>

#include<cmath>

#include<ctime> //header for time functions

using namespace std;

int main () {

     int tDate; int tMonth; int tYear; //today's date

    int bDate; int bMonth; int bYear; //birthdate

    int hour; int min; int sec;       //current time

    int resultDate, resultMonth, resultYear; //the difference

    

    //Getting today's date and current time

    time_t result;

    result = time(NULL); //getting current time and date in long seconds

    struct tm* tp = localtime(&result); //converting current (local)time into a struct for time attributes.

    tMonth = tp->tm_mon + 1;   //month since january, march would be 2, add 1.

    tDate = tp->tm_mday;

    tYear = tp->tm_year + 1900; //year since 1900, 2008 would be 108

    hour   = tp->tm_hour;

    min    = tp->tm_min;

    sec    = tp->tm_sec;

   //////////////////////////////

     //Displaying Date and time

    cout << "Today's Date is "<< tMonth <<" " << tDate <<" "<< tYear <<endl;

   cout << "and the time is "<< hour<<":"<< min << ":" << sec << endl;

//Birthdate, user input

    cout << "Please insert month of your birth date: "<<endl;

    cin >> bMonth;

     cout << "Please insert the date of birth: "<<endl;

    cin >> bDate;

     cout << "Please insert the birth year: "<<endl;

    cin >> bYear;

     //just a sample for output

    //You need to use if-statements to display correct age

    resultDate = tDate - bDate;

    resultMonth = tMonth - bMonth;

    resultYear = tYear - bYear;

          cout << "Your age is: " << resultYear << " year(s) "

         << resultMonth << " month(s) and "

         << resultDate << " day(s)." << endl

         << hour << " hour(s) "

         << min   << " min(s) "

         << sec   << " second(s)."<< endl;

    return 0;

}

Sample code to read data from a text file and sort it

#include <fstream>

#include <string>

#include <iostream>

using namespace std;

const int MAX = 9999; // create a constant value for 9999

int main()

{

            double numbers[MAX]; // create a array of doubles at max size

            int arraysize = 0; // this will be our array counter

            ifstream fin;

            ofstream fout;

            string fname;

            fin.open("data.txt"); // I deleted the if statement and just open the file

            fin >> numbers[arraysize]; // reads in the first line

            while (fin) // you can also do a eof loop with just the input variable

            {

                        arraysize++; // counts how many numbers are in the file;

                        fin >> numbers[arraysize]; // reads in the next lines

            }

            numbers[arraysize] = '';

            cout << "Unsorted Numbers: " << endl << endl;

            for (int i = 0; numbers[i] != ''; i++)

            {

                        cout << numbers[i] << endl;

            }

            double temp; //place holder when values are interchanged

            for (int i = 0; i < arraysize - 1; i++)

                        for (int j = 0; j < arraysize - (i + 1); j++)

                                    if (numbers[j] < numbers[j + 1])

                                    {

                                                temp = numbers[j];

                                                numbers[j] = numbers[j + 1];

                                                numbers[j + 1] = temp;

                                    }

            cout << endl << "Sorted Numbers:" << endl << endl;

            for (int i = 0; i < arraysize; i++)

            {

                        cout << numbers[i] << endl;

            }

cout << "Please enter name for binary file: ";

                        cin >> fname;

                        fout.open(fname.c_str());

            for (int i = 0; i < arraysize; i++)

            {

                       

                        fout << numbers[i] << endl;

                       

            }

fout.close();

            system("PAUSE");

            return 0;

}

Note- all the above code samples can be helpful for the given question to be answered.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote