Question: Files, Vectors & LINQ Our most recent lecture(s) covered a lot of new material. This assignment gives you the opportunity to truly understand some of

Files, Vectors & LINQ Our most recent lecture(s) covered a lot of new material. This assignment gives you the opportunity to truly understand some of the new concepts introduced therein. This assignment includes a total of 4 files in Contacts.zip:

The instructions (this document) The data: us-100000.csv (holds 100,000 contacts) Cpplinq.hpp: provides LINQ functions Contacts.cpp: the main program.

THE CONTACTS.CPP:

#include // Include the string library.

#include // Include to manipulate files.

#include // Include to use vectors.

#include // Include to use stringstream.

#include

#include

#include"cpplinq.hpp"

using namespace std;

class contact {

public:

string firstName;

string lastName;

string companyName;

string address;

string city;

string county;

string state;

string zip;

string phone1;

string phone2;

string email;

string web;

void out() {

cout << this->lastName << ", " << this->firstName << endl;

cout << "---------------------------------------------------" << endl;

cout << this->companyName << endl;

cout << this->address << endl;

cout << this->city << endl;

cout << this->county << endl;

cout << this->state << endl;

cout << this->zip << endl;

cout << this->phone1 << endl;

cout << this->phone2 << endl;

cout << this->email << endl;

cout << this->web << endl;

cout << endl;

}

;

};

int computes_a_sum();

void loadContacts();

void loadContacts(vector&contacts);

void printContacts(vector&contacts, int n);

vector findContactsByLastName(vector&contacts, string name);

int main() {

cout << "Loading contacts. Please wait..." << endl; // prints Contacts

vector contacts;

loadContacts(contacts);

cout << "We loaded " << contacts.size() << " contacts" << endl;

vector results = findContactsByLastName(contacts, "M");

cout << "We found " << results.size() << " contacts!" << endl<

// print first five results

printContacts(results, 5);

return 0;

}

int computes_a_sum()

{

using namespace cpplinq;

int ints[] = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 4 };

auto result = from_array(ints) >> where([](int i) {return i%2 ==0;}) // Keep only even numbers

>> sum() // Sum remaining numbers

;

return result;

}

// Return a vector containing contacts where last name

// begins with or matches the criteria.

vector findContactsByLastName(vector&contacts,string criteria)

{

using namespace cpplinq;

auto result =

from(contacts)

>> where(

[=](contact const & c) {return c.lastName.find(criteria)==0;})

>> to_vector();

return result;

}

// Prints contacts to console

void printContacts(vector&contacts, int n=-1)

{

if (contacts.size()==0)

{

cout << "[nothing to print.]"<

return;

}

if (n==-1) // default to printing all contacts

n = contacts.size();

for (int i = 0; i < n; i++) {

contacts[i].out();

}

}

// load contacts from local delimited file

void loadContacts(vector&contacts)

{

ifstream file("us-100000.csv");

contact c;

while (file.good()) {

c = contact();

getline(file, c.firstName, ',');

getline(file, c.lastName, ',');

getline(file, c.companyName, ',');

getline(file, c.address, ',');

getline(file, c.city, ',');

getline(file, c.county, ',');

getline(file, c.state, ',');

getline(file, c.zip, ',');

getline(file, c.phone1, ',');

getline(file, c.phone2, ',');

getline(file, c.email, ',');

getline(file, c.web, ' ');

contacts.push_back(c);

}

std::cout << "File Finished" << std::endl;

}

THE CPPLINQ.HPP:

// Copyright (c) Mrten Rnge. // ---------------------------------------------------------------------------------------------- // This source code is subject to terms and conditions of the Microsoft Public License. A // copy of the license can be found in the License.html file at the root of this distribution. // If you cannot locate the Microsoft Public License, please send an email to // dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound // by the terms of the Microsoft Public License.

(too lengthy to paste, but if need me to paste please tell me)

Cpplinq.hpp and Contacts.cpp should reside together in the same folder. Us- 100000.csv contains the actual data in comma-delimited form. You will need to place this file in your /debug or /release folder. Since the compiled program runs from that folder, my code will only look in the same folder the program is running from. Where you place this file might depend on your particular environment. Use Google to learn where your program will look by default. If you cannot get this to work properly, you may avoid pathing issues by supplying a fully qualified path to where the data file actually resides on your system. Note that in some environments you can just leave the file where the cpp file is.

First, simply use the source code as-is. That is, try to compile the code without changing it, and run it. You should see the following output:

Loading contacts. Please wait... File Finished We loaded 1000001 contacts We found 85268 contacts! Morasca, Simona --------------------------------------------------- Chapman| Ross E Esq 3 Mcauley Dr Ashland Ashland OH 44805 419-503-2484 419-800-6759 simona@morasca.com http://www.chapmanrosseesq.com Marrier, Kris --------------------------------------------------- King| Christopher A Esq 228 Runamuck Pl #2808 CS3060-001 Wk 06; HW 01: Files, Vectors & LINQ - Due: Tuesday (03:00pm) Oct 03, 2017 Baltimore Baltimore City MD 21224 410-655-8723 410-804-4694 http://www.kingchristopheraesq.com Maclead, Abel --------------------------------------------------- Rangoni Of Florence 37275 St Rt 17m M Middle Island Suffolk NY 11953 631-335-3414 631-677-3675 http://www.rangoniofflorence.com Malet, Blair --------------------------------------------------- Bollinger Mach Shp & Shipyard 209 Decker Dr Philadelphia Philadelphia PA 19132 215-907-9111 215-794-4519 bmalet@yahoo.com http://www.bollingermachshpshipyard.com Mastella, Marjory --------------------------------------------------- Vicon Corporation 71 San Mateo Ave Wayne Delaware PA 19087 610-814-5533 610-379-7125 mmastella@mastella.com http://www.viconcorporation.com

The program loads all the contacts, searches for all contacts where last name begins with M, and displays the first 5 results out of 85,268 contacts found.

WHAT I AM SUPPOSED TO DO:

Now Its Your Turn! Modify the code I provided to you so that you can answer the following questions. Submit ALL your answers in a Word doc, below the repeated question, along with your source code. Zip it all up. DO NOT INCLUDE THE DATA FILE IN THE ZIP! If you do, points will be deducted to bring you down at least one letter grade.

To learn more about CppLinq, go here: https://cpplinq.codeplex.com/

Provide Answers for the Following Questions: (1) How many contacts are there where last name begins with st? (2) How many contacts are there where last name begin with z? (3) How many contacts live in CA? (4) How many contacts are there who have emails with aol.com? (5) How many contacts are there with first names starting with ba while their last names start with f? (6) How many contacts are there with first names starting with t while their last names start with f and who live in MI? (7) Sort your contacts list by State. List the first 10 contacts you see after performing the sort. (8) Sort contacts by state and city. List the first 10 contacts you see after performing the sort. (9) Sort contacts by state, city, and zip. List the first 10 contacts you see after performing the sort.

Note: Understand that if I say for problem 9 to sort by state, city, and zip this means that you are performing ONE sort. This sort will list people in order by state first, city second, and then by zip. So, if you had 100 people who lived in MI, people who live in the city of Ann Arbor would be listed before those who live in the city of Azalia. Furthermore, those who live in Ann Arbor with zip code of 48103 would be listed before those who live in Ann Arbor with zip code of 48109. Problem 9 is an example of a report with a first, second, and third sort order.

(I HAVE ANSWERS FOR THESE, BUT I NEED TO KNOW IF I AM SOLVING THEM CORRECTLY. IF POSSIBLE, CAN CODE BE PROVIDED FOR EACH PROBLEM? IF NOT, A GENERAL DESCRIPTION OF HOW TO GET THERE? THANK YOU)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!