Pages

Wednesday, February 5, 2014

lab 2

3a
Transmission Delay:
m/r= 10mb/1gbps
10mb= 83886080bits
1gbps= 1000000000bits
m/r= 0.083886 ms

Propagation delay:
speed of light(C)= 299792458
2/3(c)= 199861639
36000/199861639= 0.000180126


Latency= 0.083886 + 0.000180126= 0.08406613

3b
Transmission Delay:
m/r= 10mb/10bps
10mb= 83886080bits
10bps= 10 bits
m/r= 838860

Propagation delay:
speed of light(C)= 299792458
2/3(c)= 199861639
2/199861639= 0.000000001000692


Latency= 0.000000001000692 + 838860= 838860.000000001


4

open- opens the function and makes the connection between a file and file descriptor.
connect- connects a function by attempting to connect to a socket
write- tries to write nbyte from the buffer pointed to the by buf to the file associated with the open file descriptor.
close- closes a file descriptor, that way it doesn't go back to any file and may be recycled.
read- tries to read to count bytes from file descriptor fd into the buffer starting at buf.
pipe- makes a pipe, a unidirectional daa channel that can be used for interprocess communication.







5 fwrite

#include <stdio.h>

struct clientData {
    int acctNum;
    char lastName[ 15 ];
    char firstName[ 10 ];
    double balance;
};


int main()
{
    FILE *cfPtr;
    struct clientData client = { 0, "", "", 0.0 };

    if ( ( cfPtr = fopen( "credit.dat", "r+" ) ) == NULL )
        printf( "File could not be opened.\n" );
    else {
        printf( "Enter account number "
               " ( 1 to 100, 0 to end input )\n? " );
        scanf( "%d", &client.acctNum );

        while ( client.acctNum != 0 ) {
            printf( "Enter lastname, firstname, balance\n? " );
            fscanf( stdin, "%s%s%lf", client.lastName, client.firstName, &client.balance );
            fseek( cfPtr, ( client.acctNum - 1 ) * sizeof( struct clientData ), SEEK_SET );
            fwrite( &client, sizeof( struct clientData ), 1, cfPtr );
            printf( "Enter account number\n? " );
            scanf( "%d", &client.acctNum );
        }

        fclose( cfPtr );
    }

    return 0;
}






fread

#include <stdio.h>

struct clientData {
    int acctNum;
    char lastName[ 15 ];
    char firstName[ 10 ];
    double balance;
};


int main()
{
    FILE *cfPtr;
    struct clientData client = { 0, "", "", 0.0 };

    if ( ( cfPtr = fopen( "credit.dat", "r" ) ) == NULL )
        printf( "File could not be opened.\n" );
    else {
        printf( "%-6s%-16s%-11s%10s\n", "Acct", "Last Name", "First Name", "Balance" );

        while ( !feof( cfPtr ) ) {
            fread( &client, sizeof( struct clientData ), 1, cfPtr );

            if ( client.acctNum != 0 )
                printf( "%-6d%-16s%-11s%10.2f\n",
                      client.acctNum, client.lastName,
                      client.firstName, client.balance );
        }

        fclose( cfPtr );
    }

    return 0;
}







1 comment:

Note: Only a member of this blog may post a comment.