lab-1-sec-4-Yash

Embed Size (px)

Citation preview

  • 7/26/2019 lab-1-sec-4-Yash

    1/4

    BITS, PILANI (RAJASTHAN)

    First Semester 2011-12

    CS C341/ IS C361 Data Structures and Algorithms

    Lab#1 SEC-4 (Thursday, 11th

    Aug.)

    ADT ShuffleList

    Duration: 2 hours 30 minutes

    General Instructions for ProgrammingLinux command to download the labsheet and support files to the local machine

    $scp -r @blade3:~/ .

    Linux command to upload all the program files back to the server.

    $ scp -r username@blade3:~

    1. All inputs to the program must be either (a) command line arguments (b) or read from a file(other than stdin). DO NOT READ anything from stdin and DO NOT USE PROMPTS likePlease enter a number .2. You are required to write the output to a file (other than stdout) and errors if any to a differentoutput channel (stderr or another file).3. Use standard C coding conventions for multi-file programs. Separate the following: interfaces

    of functions (use a .h file), data type definitions (use another .h file), ADT / algorithmimplementation (use a .c file), and driver/test code (use another .c code). In general, eachmodule has to be written in separatec files.

    4. All files related to a lab mustbe put inside a single directory by the name of the lab (lab1, lab2,etc.).

    Problem StatementWrite a program to riffle shuffle threecountry teams of robots to build the world team(named SuperR) of robots. Each country has number of state teams. State team consistsof number of robots. First we need to create country team by taking the robot withmaximum number of features from the first state team of robots as first element of thecountry team then the first robot with maximum number of features from the second stateteam of robots as second element of the country team and so on and then secondmaximum of first state and so on till all the elements of state teams are exhausted.

    Likewise we create all country teams. Finally we create the world team by following thesame procedure.

  • 7/26/2019 lab-1-sec-4-Yash

    2/4

    Data Structures to be used1. Country Team: stores country name and number of state teams (i.e. size) and

    maintains the list of states. In a country, the number of states is not fixed.There are three countries in all.

    2. State Team: stores state name and number of robots. This maintains the list ofrobots in a state team. The number of robots in a team is not fixed.

    3.

    Robot Details:

    a.

    RID:Unique identity number of the robot (i.e. 1001,1002 etc.)b. RType :Category to which robot belongs (i.e. T1, T2 etc.)c. RMake : Company name (i.e. Samsung, Sony etc.)

    d. Rweight:Robot weight (i.e. 100.5, 200.8 etc.)e. Rfeatures:Number of features (i.e. 23,34 etc.)f. Rspeed: Robot Speed (23.5, 35.5 etc.)

    Instance of StateTeam is as follows

    R1 R2 R3 R4

    Step 1: Create new type definition(s) (file: Team.h)(a)Create a type definition for a Robotwith all the above details of Robot. (b)Create a type definition for a node in a linked list that contains a Robot. You need

    to create a linked list of Robot.(c)Create a type definition for a StateRTeamwhich stores robot list as a linked list.

    (d)

    Create a type definition for a CountryRTeamas an array of structure containingstates as a linked list.

    Step 2: Design Team ADT with the following Operations: (file: TeamOps.h)Following are the Team ADT operations.

    (a)Team createTeamR():creates an empty list.(b)Team populateList(Team r,FILE *f1):reads robot data from the file and insert

    it into the list.(c)void printList(LINK head,FILE *f1):prints the list data into a output file(d)Team InsertRobot(Robot rl, Team sl):adds the robot element in the linked list.

    Step 3: Implement the above operations for TeamADT. (file: TeamOps.c)

    Step 4: Create driver file (file worldteam.c) that can read input files corresponding tovarious country teams. Write a main procedure with command line arguments for threeinput file names and an output file name.

    Also write the procedure shuffleList(a)Team shuffleRTeam(StateRTeam *srt):

    Procedure shuffleList creates a country team by taking the robot with maxnumber of features from first state team and then robot with max number offeatures from second state team and so on.This will continue till end of list.

    NULL

    RAJ 4 first

  • 7/26/2019 lab-1-sec-4-Yash

    3/4

    In the end, when only one state team is left, append all the elements indecreasing order of feature values.

    (b)Create the worldR with 10 elements using above shuffle procedure.

    The code can be executed by invoking the executable as./EXEFILE country.txt state.txt robotdata.txt outputfile.

    Example for shuffling based on Number of features:

    RID RType RMake Rweight Rfeatures Rspped(TeamA)List1:1001 T2 Microsoft 23.000000 36 34.0000001002 T1 Samsung 34.000000 35 34.000000--------------------------

    (TeamB)List2:2001 R3 IBM 45.000000 33 23.0000002002 R2 Microsoft 23.000000 32 34.0000002003 R1 IndiaSamsung 34.000000 31 34.00000--------------------------

    ShuffleList:2003 R1 IndiaSamsung 34.000000 31 34.0000002002 R2 Microsoft 23.000000 32 34.0000001002 T1 Samsung 34.000000 35 34.0000002001 R3 IBM 45.000000 33 23.0000001001 T2 Microsoft 23.000000 36 34.000000--------------------------

    Files :Input files: country.txt, state.txt, robotdata.txt

    Deliverables : Team.h, TeamOps.h, TeamOps.c, worldteam.c.,output.txtCreate a Makefile.

    Sample Input files

    Country.txtCountry Name$No. of state TeamsIndia$4China$2Japan$2

    StateTeams.txt

    CountryName$StateTeamName$Number of robotsIndia$RAJ$3India$MS$2India$HP$1India$UP$2China$WR$2China$ER$1Japan$HK$2Japan$HU$1

  • 7/26/2019 lab-1-sec-4-Yash

    4/4

    Robots.txtIndia$RAJ1001$T1$Sony$34.4$34$24.51002$T2$Samsung$31.4$26$24.51003$T1$Tera$24.4$25$24.5India$MS2001$T1$Joky$24.4$11$14.52002$T2$Sony$31.4$12$44.5India$HP3001$T1$HP$31.4$23$24.5India$UP4001$T1$Nokia$54.4$54$25.54002$T2$Sony$24.4$22$21.5China$WR5001$T2$Motorola$38.4$56$22.55002$T1$Sony$14.4$12$14.5China$ER6001$T1$HP$34.4$44$24.5Japan$HK7001$T2$Mono$38.4$24$42.5

    7002$T1$Sony$14.4$42$19.5Japan$HU8001$T1$HP$34.4$26$24.5