代写lab | c++代写 | 数据结构代写 – CSC230 Lab 7

CSC230 Lab 7

代写lab | 代写lab | c++代写 | 数据结构代写 – 这个项目是lab代写的代写题目

lab代写 代写lab


Goal : This lab includes function and linked list, fstream, and eof().

Please try your best to finish the lab in class, and submit it to CANVAS.

In this lab, please write a YournameLab7.cpp file. There is a main function in this file. Please define one more function in the lab. The new function defined by you should be insert ().

In Lab 6 , we read contents from a file and append the contents to a singly linked list. In this lab, we will modify the functionality implemented by Lab 6.

  • In this lab, insert the new node to the singly linked list IN increasing ORDER (SSN). Please note that you MUST use singly linked list to implement this lab.
  • Just like Lab6, Lab7.cpp reads contents from an input file, which is sample.txt in todays lab. Each row of the input file has a leading char, followed by a string of SSN, and first name and last name.
  • Whenever Lab6.cpp reads one row from the file, it stores SSN and the corresponding name (including both first name and last name) to a singly linked list. After the whole input file is processed, the program prompts the user to type an SSN, then it will search the SSN in the singly linked list.
  • If there is a match, the program prints out the index value of the node. Suppose the first node has index value 0. If there is no match in the list, print out -1. After printing out the searching result, the program prints out the SSN values node by node. For example,
jli$ ./a.out sample.txt
Input a SSN:
038249140
Found at: 0
List contents:
038249140
138863035
151682139
173421651
364523152
364523152
478362801
493582998
545309496
652802112
766434955
815904565
912741495
926654750
jli$ ./a.out sample.txt
Input a SSN:
545309496
Found at: 8
List contents:
038249140
138863035
151682139
173421651
364523152
364523152
478362801
493582998
545309496
652802112
766434955
815904565
912741495
926654750

In this lab, you can use fstream library to read file. An example code is listed as follows:

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]){
int x, y, z;
fstream input(argv[1]);
while(!input.eof()){
input >> x >> y >> z;
}
input.close();
}

Hints & Requirements

  • Only when the current list is empty or the first node has a larger value than the new SSN, you insert the new node as the first node of the list.
  • Use a Node pointer p start from head pointer, make it go through the list until p->next is NULL or p->next has the SSN larger than the new SSN. Insert the new node after p.
  • The Node defined in the slides has only one user variable, val. You can define multiple variables inside one node. For example, you can define string SSN; and string name; inside the node.
  • Do NOT define any array in this lab. You do not need array in this lab.

Wrap up

When you’re done, jar three files to lab6.jar

jar cvf lab7.jar *

Submit lab7.jar to Canvas.

Make sure your logout before you leave!

If you cannot finish lab in class, please save all your files. Next time your login the computer in the lab, you can continue work on your files. Please save them before your logout. If you work in a Linux lab, please save the file to your machine. However, if you are working in the Mac lab, please save the file to a CLOUD. The Mac machine will erase everything you saved once you logout.