bridge course 2nd year cse and it

Upload: ashmeet-sabby

Post on 08-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 bridge course 2nd year CSE and IT

    1/13

    Bridge Course Assignment (C Language)

    Bridge Course Assignment (C Language)

    1.

    Write a menu driven program for transaction processing.

    A file old master.dat of a bank contains the records of saving fund account of its customers in

    ascending order of account numbers. The format of record should be:

    Name

    Account_no

    Balance_amt

    A file tansaction.dat contains the details about transaction done to accounts on a particular day.It also

    contains the records in the ascending order of account numbers. The format of each record should

    be:

    Account_no

    Transaction_type

    Transaction_amt

    The field Transaction_amt contains the amount withdrawn or deposited to the A/C depending upon the

    value of Transaction_type being 0 or 1 respectively.

    The program will read these two files and does the transaction processing and will generate third file

    called newmaster.dat.

    Implementation Notes:

    Menu should be displayed so that the possible actions can be conveniently carried out

    by the user: Menu

    Create oldmaster file ----- 0

    Create transaction file ------ 1

    Generate newmaster file ----- 2

    Show contents of a file ----- 3

    Quit ---- 4

    Structure should be used for Account record and Transaction Records using above

    format

    Use switch statement and do-while for making menu driven program.

    Use different functions for creating different files. For Example: create_o for creating

    master file, create_T for transaction file and showfile function for displaying records

    information of particular account.

    Page 1 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    2/13

    Bridge Course Assignment (C Language)

    2.

    Seat Reservation Problem

    Write a menu driven program for seat reservation in a train.

    Seat allocate array is of 10*20 and each row and column represent A1,A2....; B1,B2.....; ........J1,J2...

    and so on i.e. row are A to J whereas column starts from 0 to 19.Each cell in the table represent either 0

    or 1. 0 represent seat available, 1 represent seat reserved.

    Seat allocation starts from highest to lowest. And row j is highest, I is second highest and so on. Max

    20 seats can be booked at a time. If seat is available print the seat number like "B2" i.e (2 row, 3 col)

    and seat is booked." otherwise Print "Seat is not available."

    Notes on Implementation of this program:

    Menu should be made so that user can enter his/her choice that what he/she wish to

    do: reserve seats or unreserved his/her seat. Use switch statement for asking persons choice.

    Use structure or union for seat allocation and use following format.

    {char name[]; int seats; boolean isseatempty;}

    Write function seatallot(int noofperson) to allocate seat with seat number printed for

    the each name and display proper message if there is no seat left to reserve.

    Each small subtask should be implemented using functions. And use only call by

    reference method for calling every function.

    Using above data generate a file called reservationdetail.dat which have all the details

    of reserved seats with details of person and append this file each time a new reservation is

    done.

    Also generate a file called unreservedseats.dat which would be read every time a

    reservation has to be done or appended if seats are unreserved by any person.

    Use proper data structure like link list, stack or queue for number of seats and

    number of users.The program has to create a linked list containing relevant information about

    the users. The relevant information about the users is stored in a text file users.txt

    Page 2 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    3/13

    Bridge Course Assignment (C Language)

    The program has to print on the screen the results for each reservation or unreserved

    process.

    Make use of malloc()/calloc() and realloc() for redefining data structures.

    3.

    Write a program that will receive a filename and a line of text as common line arguments and write the

    text to the file.

    For Example:

    The command line is

    F12-7 TEXT AAAAAABBBBBBCCCCCCDDDDDDEEEEEEFFFFFFGGGGGG

    Each word in the command line is an argument to the main and therefore the total number of argument

    is 9.The argument vector argv[1] points to the string TEXT and therefore the statement

    fp=fopen(argv[1],w);

    Will opens a file with the name TEXT.

    Use only for-loop for writing content of the file to screen

    Use only while loop for writing the arguments from memory.

    The contents of file should be then copied to BINARY FILE called BinaryTEXT.

    4.

    Develop a Top-Down modular program that will perform tasks:

    Read two integerarrays with unsorted elements.

    Sort Them in ascending order using only Bubble sort

    Merge the sorted arrays using Merge sort.

    Print the sorted list using function called display() .

    Use functions for carrying out each of the above tasks.

    Page 3 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    4/13

    Bridge Course Assignment (C Language)

    Use properfunction declarations;

    Use only call by reference method of function calling.

    The main function should have only function calls and nothing else.

    5.

    Reordering a list of Strings

    Write a program to sort a list of strings alphabetically.

    Allow the program to accept an unspecified number of strings, until a string is entered whose first three

    characters are END (in either upper- or lowercase).

    The program will count the strings as they are entered, ignoring the last string which contains END.

    In this program, the character array must be defined as a pointer to a character.

    Make use ofmalloc() library function for allocating memory to the pointer variable.

    Use yourown functions to compare two strings and copy one string to another instead of library

    functions strcmp and strcpy.

    Use only do-while loop for a stopping condition and for loop for interchanging two strings.

    After rearranging, copy the alphabetically arranged strings into a TEXT file using file handling.

    6.

    Write a program which develops a simple mailing list that uses an array of structures to hold the

    address information.

    Notes on implementation:-

    The stored information includes name, street, city, state and zip code.

    The address information is held in an array of address structure. The format of

    structure should be :

    Struct address{

    char name[30];

    char street[40];

    char city[20];

    char state[3];

    unsigned long int zip;

    } address_list[MAX];

    Make use of DOUBLY LINKED LIST.

    Make a function init_list() which prepares the structure array for use by putting a

    null character into first byte of the name field for each structure in the array.

    Page 4 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    5/13

    Bridge Course Assignment (C Language)

    Make a function called menu_select() function to display the menu and returns the

    users selection.

    Make enter() function which prompts the user for input and stores the information in

    the next free structure. If the array is full, the message: List is full is displayed. find_free()

    searches the structure array for an unused element.

    Make function delete() to specify the index of the adres that needs to be deleted. The

    function should then put a NULL character in the first character position of the name field.

    Function list() function prints the entire mailing list on the screen

    Make use of register variable in init_list() function.

    Make use of macro and define it properly to use in main program.

    To save and load the mailing list database, use save() and load() functions. Use

    fread() and fwrite() functions in the save and load functions.

    Use gets() function instead of scanf function.

    7.

    Write a C program to find the route from New York to Los Angeles which requires a database that

    contains the information about XYZs flights. Each entry in the database must contain the departure &

    destination cities, the distance between them and a flag that aids in backtracking.

    Implementation Notes:

    Make a function route() which prints the path as well as the total distance.

    This function uses DEPTH_FIRST SEARCH.

    Use Mcaro and push , pop functions with proper use of stack.

    Use function assert_flight() to place the individual entries into the database and

    setup() function initializes all the flight information. The global f_pos function holds the index

    of the last item in the database.

    8.

    Write a program to print those strings which are palindromes from a set of strings stored in the

    following array of pointers to strings.

    static char *s[]={

    MalayalaM,

    To really mess things up,

    one needs to know c!!,

    able was I err I saw elba

    };

    Use your own functions instead of strcpy() and strrev() and strcmp().

    Page 5 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    6/13

    Bridge Course Assignment (C Language)

    9.

    Imagine a tollbooth with a function called tollbooth ().

    The two data items are of type unsigned int to hold the total number of cars and a type double to hold

    the total amount of money collected.

    Notes on Implementation:

    Make a function which initializes both these to 0.

    A function called payingCar() increments the car total and adds 0.50 to the cash total.

    Another function, called nopayCar() increments the car total but adds nothing to the

    cash total.

    Finally, a member function called display() displays the two totals.

    This program should allow the user to push one key to count a paying car, another tocount a non-paying car. Pushing the Esc key should cause the program to print out the total

    cars and total cash and then exit.

    Program should me menu driven and should use while loop.

    Amount should be displayed up to four places of decimal.

    10.

    Write a program to compress the content of a file such that the multiple blanks are eliminated. Store the

    compressed message in another string. Also write a decompress program to get back the original stringwith all its spaces restored.

    Use static unsigned char as data type.

    Read the file text.txt where the string to be compress is stored, compress it such that

    multiple blanks are eliminated and store the output into another file called compressed.dat.

    Make functions to do all these subtasks.

    11.

    Write a program that uses self referential structure to create a linked list of nodes of following

    structure. While creating the linked list, the student data is read. The list is also travelled to print the

    data.

    The self referential structure is like this.

    The format of self-referential structure for the purpose of creating a node of the linked list is:

    struct stud {

    Page 6 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    7/13

    Bridge Course Assignment (C Language)

    char name[20];

    int roll;

    struct stud next;

    };

    Make use ofsizeof operator for determining the size of structure.

    Assume that the number of students in the list are not known; Use malloc() for first

    node and new node memory allocation.

    The list of students is split into 2 sub-lists pointed by 2 pointers: front_half and

    back_half.

    The front_half points to the front half of the list and the back_half to the rest of the list. If the number

    of Students is odd, the extra students should go in the front half list.

    12.

    A positive integer is called Nasty if it has at least 2 pairs of positive integer factors such that the

    difference of one pair equals the sum of the other pair.

    For Example:

    The number 6 is nasty.

    1, 6 are factors of 6 : 6-1=5

    2, 3 are factors of 6 : 2+3=5

    The format to be used for structure is:

    Struct factorpair

    {

    int factor1,factor2;

    int difference;

    int sum;

    };

    This structure would be used to store a pair of factors, its difference and its sum.

    All factors of number under examination would be stored as an array of factorpair.

    Use enum nastynumber{true , false};

    With a nested loop, the difference of a pair of factors would be compared with sum

    of other pair of factors to find if the number is nasty or not.

    13.

    Page 7 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    8/13

    Bridge Course Assignment (C Language)

    Write a program in C using command line argument to perform as a calculator. The usage of the

    program is as under:

    C:> calc

    Implementation notes:

    Here calc is the name of your program.

    Operator can be +, - , / and * for addition, subtraction, division & multiplication

    respectively and user can enter integers or floating point numbers.

    Also display input error message.

    The program should be menu driven and should use only switch statement for

    taking users choice.

    The output must be up to four decimal in case of floating point operations.

    All operations should be done using functions.

    14.

    Write a program in C that will accept Empno, name & basic salary of an employee. Program then

    calculate DA, HRA, PF, IT, Total allowances (TA), Total deduction (TD), Gross Salary (GS), Net

    salary. Income will be deducted monthly by dividing the total income tax which is 10% only if the

    annual gross pay exceeds 150,000.00.

    Calculation should be done as under:

    DA is 35% of basic

    HRA is 20% of basic

    PF is 8.5 % of basic

    For Income Tax

    If Annual Gross salary (AGS) > 150,000.00 then IT for year =10% of Exceed amount

    Total allowance is DA+ HRA

    Total deduction is PF + IT

    Gross salary = Basic salary + Total allowance + total deduction

    Net salary = Gross salary total deduction

    Display the salary slip in the following format:

    Employee No:

    Name :

    Basic Salary Allowance Deduction Gross Sal Net Salary

    ? DA : PF:

    HRA: IT:

    Page 8 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    9/13

    Bridge Course Assignment (C Language)

    TA : TD:

    Implementation Notes:

    The output must be up to four places of decimal.

    Use structure for employee details and number of employee are not known in

    advance. so you can also assign memory dynamically.

    Use function for each subtasks e.g. for calculating income tax use incometax()

    function. Use call by reference method for passing parameters to different functions.

    If you dont want to pass parameters then define function globally.

    The salary slip generated must be stored in text files so that it can be used later also.

    15.

    Write a program to define a data type for storing complex numbers and implement addition,subtraction, and multiplication, conjugate and modulus operations for the defined data type.

    Use structure of following format:

    struct complex

    {

    int real;

    int imaginary;

    };

    typedef struct complex COMP;

    Make functions for all the operations like addition, multiplication etc.

    Use string library functions.

    16.

    Define a structure data type called DATE for storing dates.The type contains 3 integer members: Day,Month and year.

    Implement the following operations for the defined data type.

    isvalid() : checks whether the entered date is valid or not.

    For Example: 31-02-2009 is not a valid date since Feb does not have 31 days.

    nextdate(): finds the next date

    For example: if the current date is 31-1-2009 then the result of next date operation is 1 -2-2009

    datedifference(): find the difference between two dates.

    Define a structure using the following format:

    Page 9 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    10/13

    Bridge Course Assignment (C Language)

    struct date

    {

    int date;

    int month;

    int year;

    }

    typedef struct date DATE;

    Implement this program using above structure and variables.

    17.

    Shooting craps program

    Crap is a popular dice game in which you throw a pair of dice one or more times until you either win or

    loose. The game can be simulated on a computer by generating random numbers rather than actually

    throwing the dice.

    There are two ways to win in craps. You can throw dice once and obtain a score of either 7,11 or you

    can obtain a 4,5,6,8,9 or 10 on the first throw and then repeat the same score on a subsequent throw

    before obtain a 7. Conversely there are two ways to lose. You can throw the dice once and obtain a 2, 3

    or 12; or you can obtain a 4, 5, 6, 8, 9 or 10. On the first throw then obtain a 7 on the subsequent throw

    before repeating your original score.

    Develop the game interactively so that one throw of the dice will be simulated each time you press the

    enter key. A message will then appear indicating the outcome of each throw. At the end of each game

    you will be asked whether or not you want to continue to play.

    Implementation Notes:

    Make 2 separate files; first file contains main, whereas the second file contains the

    functions play and throw.

    Make play () as an external function, so it can be accessed from main.

    Define throw () as static function confining its scope to the second file.

    Use while and switch case so that can be found out that you win or lose.

    Use macro SEED 12345 to initialize the random number generator.

    18.

    Write a C program foradding 2 Tables of numbers.

    Define three One-Dimensional arrays of pointers, such that each array element will point to

    a one-dimensional array of integer.

    Page 10 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    11/13

    Bridge Course Assignment (C Language)

    Use malloc() to allocate an initial block of memory . These malloc statements should be

    placed within a for-loop in order to allocate a block of memory for each of the non-zero rows

    within the 3 Tables.

    Make Functions like readinput(), writeoutput() and computesums() to perform the tasks.

    19.

    Write a C program that will accept the following information for each team in a baseball or a football

    league.

    1. Team name, including the city (e.g., Pittsburgh Steelets)

    2. Number of wins

    3. Number of losses

    For a baseball team, add the following information:

    4. Number of hits

    5. Number of runs

    6. Number of errors

    7. Number of extra-inning games

    Similarly, add the following information for a football team:

    4. Number of ties

    5. Number of touchdowns

    6. Number of field goals

    7. Number of turnovers

    8. Total yards gained (season total)

    9. Total yards given up to opponents

    Implementation Notes:

    Enter this information for all of the teams in the league. Then reorder and print the list of

    teams according to their-win-lose records, using the reordering techniques.

    Store the information in an array of structures, where each array element (i.e., each

    structure) contains the information for a single team.

    Make use of a union to represent the variable information (either baseball or football) that

    is included as a part of the structure. This union should itself contain two structures, one for

    baseball-related statistics and the other for the football related statistics

    Test the program using a current set of league statistics. Ideally, the program should be tested

    using both baseball and football statistics.

    Page 11 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    12/13

    Bridge Course Assignment (C Language)

    20.

    Raising a number to a power

    The problem is to raise a number to a power. We wish to evaluate the formula y=x ^n, where x and y

    are floating point values and n can either integer or floating point.

    If n is an integer, then y can be evaluated by multiplying x by itself an appropriate number of times.

    For Example:

    The quantity x^3 could be expressed in terms of the product (x)(x)(x).

    On the other hand, if n is a floating point value, we can write log y=n log x, or y=e^ (n log x).

    In the latter case x must be a positive quantity, since we cannot take the log of zero or a negative

    quantity.

    Implementation notes:

    Define structure and union of following formats:

    typedef union {

    float fexp; /* floating point exponent */

    int nexp; /* Integer exponent */

    } nvals;

    typedef struct {

    float x; /* value to be raised to a power */

    char flag; /*f if exponent is floating point, i if exponent is integer */

    nvals exp; /* union containing exponent */

    } values;

    values a;

    Create a function called power() that will evaluate the formula y=x^n. This functionaccepts

    a structure variable (a) of type values as an argument.

    Also include a provision for generating an error message if n is a floating point exponent

    and the value of x is less than or equal to zero.

    21.

    Displaying Bit patterns

    Most versions of C do not include a library function to convert a decimal integer into binary bit pattern.

    Write a complete C program to carry out this task which will display the bit pattern corresponding to

    either a positive or a negative quantity.

    Notes:

    Page 12 of 13

  • 8/7/2019 bridge course 2nd year CSE and IT

    13/13

    Bridge Course Assignment (C Language)

    The program should be written so that it is independent of the integer word size.

    Therefore it can be used on any computer.

    Begins the program by determining he word size then assigns an appropriate initial

    value to the integer variable m. This value will be used as a mask in a bitwise and operation.

    Notice that m can contains a 1 in the leftmost bit position, and 0s in all of the other bit

    positions.

    Use do-while loop that allows multiple integer quantities to be converted into

    equivalent bit patterns.

    The computation continues until a value of 0 is entered into the computer and

    converted into succession of 0 bits.

    Use bitwise operators for shifting the positions.

    Note that all of the bits should be displayed on the same line. A blank space is

    displayed after every group of 4 bits, to enhance the legibility of the display.

    f