+ All Categories
Home > Documents > Program Record c

Program Record c

Date post: 04-Apr-2018
Category:
Upload: sumitrai666
View: 221 times
Download: 0 times
Share this document with a friend

of 35

Transcript
  • 7/31/2019 Program Record c

    1/35

    C Lab 1

    Department of Computer Science, Christ University

    Program Number : 1

    Program Name : Implementation of the various Data Types with

    Modifiers and type conversions in C

    Date Implemented : July 4, 2012___________________________________________________________________________________

    Program to Simulate Subscriber Billing & Account Management System.

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include #include

    int main(){

    char name[15];char phonenumber[15];

    int billamt,remamt1,remamt2,payment1;float payment2;

    printf("**********************************************************************\n")

    ;printf("Program to Simulate Subscriber Billing & Account Management System\n");

    printf("**********************************************************************\n")

    ;

    printf("Please enter subscriber's name, telephone number and total bill amount in INR\n");

    scanf("%s%s%d",name,phonenumber,&billamt);

    printf("**********************************************************************\n")

    ;

    printf("Subscriber %s with telephone number %s has a total bill amount of INR%d\n",name,phonenumber,billamt);

    printf("**********************************************************************\n")

    ;printf("Please enter first payment for subscriber %s, with telephone number %s, \nfor a total

    outstanding bill amount of INR %d\n",name,phonenumber,billamt);

    scanf("%d",&payment1);

    remamt1 = billamt - payment1;

    if ( remamt1 > 0 ){

    printf("\nDear %s, you have already made a payment of INR %d for your telephone number

    %s for \nyour last outstanding bill amount of INR %d\n",name,payment1,phonenumber,billamt);printf("To continue enjoying our services,please make a second payment of INR %d for

    telephone number %s\n",remamt1,phonenumber);

    scanf("%f",&payment2);

    remamt2 = remamt1 - payment2;printf("\nPayment recieved of INR %f for telephone number %s\n",payment2,phonenumber);

    printf("Payment recieved of INR in float is %0.2f\n",payment2);

    printf("Payment recieved of INR is rounded to integer is %d\n",(int)payment2);printf("Payment recieved of INR in unsigned long with u specification is %u\n",(unsigned

    long)payment2);

  • 7/31/2019 Program Record c

    2/35

    C Lab 2

    Department of Computer Science, Christ University

    printf("Payment recieved of INR in float type converted to double with f specification is

    %0.2f\n",(double)payment2);printf("Payment recieved of INR in double with g specification is %.3g\n",(double)payment2);

    printf("Payment recieved of INR in double with e specification is %.3e\n",(double)payment2);

    if ( remamt2 0 )

    {printf("Dear %s, your services have been barred for non-payment of complete outstanding bill

    amount !!!\n",name);printf("To continue enjoying our services, kindly contact customer care.\n",phonenumber);

    }getch();

    return (0);

    }

  • 7/31/2019 Program Record c

    3/35

    C Lab 3

    Department of Computer Science, Christ University

    Output:

  • 7/31/2019 Program Record c

    4/35

    C Lab 4

    Department of Computer Science, Christ University

    Program Number : 2

    Program Name : Demonstration of nested if and switch case structure

    Date Implemented : July 10, 2012___________________________________________________________________________________

    Program to enter subscriber details name and age, and perform various operations onit.

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include

    int main(){

    char name[16];

    int age;int ch;

    printf("*****************************************************************************

    *********************\n");

    printf("Demonstration of nested if and switch case structure \n");

    printf("**************************************************************************************************\n");

    while(1)

    {

    printf("\nPress 1 to Enter Subscriber Details : \nPress 2 to Modify Subscriber Details : \nPress 3 to

    Search Subscriber Details : \nPress 4 to Delete Subscriber Details : \nPress 5 to exit : " );

    scanf("%d",&ch);switch(ch){

    case 1:printf("\nThis is Add Subscriber Module using nested if-else,switch and break construct\n");

    printf("\nFunctionality of this module is added\n\n");

    printf("Enter your name: ");

    scanf("%s",&name);printf("Enter your age: ");

    scanf("%d",&age);if (age < 21)

    printf("You young whippersnapper, %s !\n", name);

    else if (age < 40)printf("%s, you're still in your prime !\n", name);

    else if (age < 60)printf("You're over the hill, %s !\n", name);

    else if (age < 80)

    printf("I bow to your wisdom, %s !\n", name);else

    printf("Are you really %d , %s ?\n", age, name);break;

    case 2:

    printf("\nThis is Modify Subscriber Module using while construct\n");

    printf("\nCore functionality of this module will be added later\n");printf("Enter your name: ");scanf("%s",&name);

    printf("Enter your age: ");

  • 7/31/2019 Program Record c

    5/35

    C Lab 5

    Department of Computer Science, Christ University

    scanf("%d",&age);

    while (age < 21){

    printf("You young whippersnapper, %s !\n", name);break;

    }

    while (age > 22 && age < 40)

    { printf("%s, you're still in your prime !\n", name);break;

    }

    while (age > 41 && age < 60){

    printf("You're over the hill, %s !\n", name);

    break;

    }while (age > 61 && age < 80)

    {printf("I bow to your wisdom, %s !\n", name);break;

    }while (age >= 80)

    {printf("Are you really %d , %s ?\n", age, name);

    break;

    }break;

    case 3:printf("\nThis is Search Subscriber Module using do while construct\n");printf("\nCore functionality of this module will be added later\n");

    printf("Enter your name: ");scanf("%s",&name);

    printf("Enter your age: ");scanf("%d",&age);

    do{

    printf("You young whippersnapper, %s !\n", name);

    break;

    }

    while (age < 21);do{

    printf("%s, you're still in your prime !\n", name);break;

    }while (age > 22 && age < 40);

    do{

    printf("You're over the hill, %s !\n", name);break;

    }while (age > 41 && age < 60);do

    {

    printf("I bow to your wisdom, %s !\n", name);

    break;

    }while (age > 61 && age < 80);

    do{

  • 7/31/2019 Program Record c

    6/35

  • 7/31/2019 Program Record c

    7/35

    C Lab 7

    Department of Computer Science, Christ University

    Output:

  • 7/31/2019 Program Record c

    8/35

    C Lab 8

    Department of Computer Science, Christ University

    Program Number : 3

    Program Name : Implementation of various control structures.

    Date Implemented : July 12, 2012

    ___________________________________________________________________________

    Program to store telecom subscriber name and age and do various operations on it.

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include

    int main(){

    char name[16];int age;

    int ch;

    printf("*****************************************************************************

    *********************\n");printf("Demonstration of all control structure(s) [if-else,while,do-while,for,switch and break

    statement] \n");

    printf("*****************************************************************************

    *********************\n");

    while(1)

    {printf("\nPress 1 to Enter Subscriber Details : \nPress 2 to Modify Subscriber Details : \nPress 3 to

    Search Subscriber Details : \nPress 4 to Delete Subscriber Details : \nPress 5 to exit : " );scanf("%d",&ch);

    switch(ch)

    {

    case 1:

    printf("\nThis is Add Subscriber Module using nested if-else,switch and break construct\n");printf("\nFunctionality of this module is added\n\n");

    printf("Enter your name: ");scanf("%s",&name);printf("Enter your age: ");

    scanf("%d",&age);

    if (age < 21)

    printf("You young whippersnapper, %s !\n", name);else if (age < 40)

    printf("%s, you're still in your prime !\n", name);else if (age < 60)

    printf("You're over the hill, %s !\n", name);

    else if (age < 80)printf("I bow to your wisdom, %s !\n", name);

    elseprintf("Are you really %d , %s ?\n", age, name);

    break;case 2:

    printf("\nThis is Modify Subscriber Module using while construct\n");

    printf("\nCore functionality of this module will be added later\n");printf("Enter your name: ");

    scanf("%s",&name);printf("Enter your age: ");

    scanf("%d",&age);

  • 7/31/2019 Program Record c

    9/35

    C Lab 9

    Department of Computer Science, Christ University

    while (age < 21)

    {printf("You young whippersnapper, %s !\n", name);

    break;}

    while (age > 22 && age < 40)

    {

    printf("%s, you're still in your prime !\n", name);break;}

    while (age > 41 && age < 60)

    {printf("You're over the hill, %s !\n", name);

    break;

    }

    while (age > 61 && age < 80){

    printf("I bow to your wisdom, %s !\n", name);break;

    }

    while (age >= 80){

    printf("Are you really %d , %s ?\n", age, name);break;

    }

    break;case 3:

    printf("\nThis is Search Subscriber Module using do while construct\n");printf("\nCore functionality of this module will be added later\n");printf("Enter your name: ");

    scanf("%s",&name);printf("Enter your age: ");

    scanf("%d",&age);do

    {printf("You young whippersnapper, %s !\n", name);

    break;

    }

    while (age < 21);

    do{

    printf("%s, you're still in your prime !\n", name);

    break;}

    while (age > 22 && age < 40);do

    {printf("You're over the hill, %s !\n", name);

    break;}

    while (age > 41 && age < 60);do{

    printf("I bow to your wisdom, %s !\n", name);

    break;

    }

    while (age > 61 && age < 80);do

    {printf("Are you really %d , %s ?\n", age, name);

  • 7/31/2019 Program Record c

    10/35

  • 7/31/2019 Program Record c

    11/35

    C Lab 11

    Department of Computer Science, Christ University

    Output:

  • 7/31/2019 Program Record c

    12/35

    C Lab 12

    Department of Computer Science, Christ University

    Program Number : 4

    Program Name : Implementation of array

    Date Implemented : July 16, 2012

    ___________________________________________________________________________

    Program to store customer name and do sum of its 3 unbilled amounts using 1-d array.

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include

    #include

    int main(){

    char customer[20];int j;

    float billamt[3];float sum=0;

    float average;

    printf("Enter customer's name :\n");

    scanf("%s",customer);

    printf("Enter last 3 unpaid bill amounts for %s :\n",customer);for(j=0;j

  • 7/31/2019 Program Record c

    13/35

  • 7/31/2019 Program Record c

    14/35

    C Lab 14

    Department of Computer Science, Christ University

    Program Number : 5

    Program Name : Implementation of multidimensional arrays.

    Date Implemented : July 18, 2012

    ___________________________________________________________________________

    Program for Implementation of two-dimensional array and show telecom circles and

    number of subscribers of all operators in that area.

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include

    int validate_number(char []);

    int main()

    {int i, j;

    int mat[2][2];

    printf("\nProgram for Implementation of two-dimensional array and show telecom circles\nand number of subscribers of all operators in that area\n");

    printf("\nProgram reads through integer table, 2*2 dimensioned which stores total area \nandnumber of subscribers and displays them on screen\n");

    printf("\nInput area and number of subscribers for 2 telecom circles/regions :\n");

    for (i = 0; i < 2; i++){

    if (i+1 == 1)printf("\nRegion %d : %s\n", i+1,"KORAMANGALA");

    if (i+1 == 2)printf("\nRegion %d : %s\n", i+1,"INDIRANAGAR");

    for (j = 0; j < 2; j++)

    {

    if (j+1 == 1)

    printf("\n%d . Area :\n",j+1);if (j+1 == 2)

    printf("\n%d . Number of Subscribers :\n",j+1);

    char temp[100];

    if(fgets(temp, 100, stdin) != NULL)

    {

    if (validate_number(temp)){

    mat[i][j] = atoi(temp);}

    else

    {printf("\nERROR !!!\nYou did not enter valid integer value.Exiting ...\n\n");

    getch();return 1;

    }

    }}

    }

    printf("\n***PRINTING AREA AND NUMBER OF SUBSCRIBER FOR ALL

    OPERATORS \nIN 2 DIFFERENT AREAS OF KARNATAKA (BANGALORE)***\n");

    for (i = 0; i < 2; i++){

    if (i+1 == 1)

    printf("\nRegion %d : %s\n", i+1,"KORAMANGALA");

  • 7/31/2019 Program Record c

    15/35

    C Lab 15

    Department of Computer Science, Christ University

    if (i+1 == 2)

    printf("\nRegion %d : %s\n", i+1,"INDIRANAGAR");for (j = 0; j < 2; j++)

    {if (j+1 == 1)

    printf("Area : ");

    if (j+1 == 2)

    { printf(", ");printf("Number of Subscribers : ");

    }

    printf("%d", mat[i][j]);}

    printf("\n");

    }

    getch();return 0;

    }

    int validate_number(char s[])

    {int valid = 1,i;

    for (i = 0; i < strlen(s) - 1; i++){

    if (!isdigit(s[i]))

    {valid = 0;

    break;}

    }

    return valid;}

  • 7/31/2019 Program Record c

    16/35

    C Lab 16

    Department of Computer Science, Christ University

    Output:

  • 7/31/2019 Program Record c

    17/35

    C Lab 17

    Department of Computer Science, Christ University

    Program Number : 6

    Program Name : Implementation of functions: call by value, call by

    reference, Passing of arrays to functions

    Date Implemented : July 23, 2012

    ___________________________________________________________________________

    Program for Implementation of functions: call by value, call by reference, Passing of

    arrays to functions on an array of customer call codes stored in memory

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include

    void modify_array( int [], int );void modify_element( int );

    int validate_number(char []);int main()

    {

    int cust_call_code[5], i;printf("\nImplementation of functions : call by value, call by reference, Passing of arrays \nto

    functions on an array of customer call codes stored in memory\n\n");

    printf("\nEnter 5 customer call codes:\n\n");

    for ( i = 0; i

  • 7/31/2019 Program Record c

    18/35

    C Lab 18

    Department of Computer Science, Christ University

    printf("\n\n\nEffects of passing array element call "

    "by value:\n\nThe value of cust_call_code[3] is %d\n", cust_call_code[3] );modify_element( cust_call_code[3] );

    printf("The value of cust_call_code[3] is %d\n", cust_call_code[3] );

    getch();

    return 0;

    }

    void modify_array(int cust_call_code[],int size)

    {

    int k;

    for(k = 0; k

  • 7/31/2019 Program Record c

    19/35

    C Lab 19

    Department of Computer Science, Christ University

    Output:

  • 7/31/2019 Program Record c

    20/35

    C Lab 20

    Department of Computer Science, Christ University

    Program Number : 7

    Program Name : Demonstration of recursion

    Date Implemented : July 25, 2012

    ___________________________________________________________________________

    Program to convert numeric telecom subscriber billed amount to words for printing in

    invoice using recursion.

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include

    #define MAX_LEN 100

    int validate_number(char []);

    void converter(long,char[]);char *one[]={" "," One"," Two"," Three"," Four"," Five"," Six"," Seven","Eight"," Nine"," Ten","

    Eleven"," Twelve"," Thirteen"," Fourteen","Fifteen"," Sixteen"," Seventeen"," Eighteen","

    Nineteen"};char *ten[]={" "," "," Twenty"," Thirty"," Forty"," Fifty"," Sixty","Seventy"," Eighty"," Ninety"};

    int main()

    {

    printf("\n**********************************************************************************************");

    printf("\n\nProgram to convert numeric telecom subscriber billed amount to words for printing ininvoice");

    printf("\n***********************************************************************

    ***********************");

    long n;printf("\n\n\t Enter any 9 digit no : ");

    char temp[MAX_LEN];if(fgets(temp, MAX_LEN, stdin) != NULL)

    {

    if (validate_number(temp))

    {n = atoi(temp);

    }else

    {

    printf("\nERROR !!!\nYou did not enter valid integer amount. Exiting ...\n\n");getch();

    return 1;}

    }

    if(n

  • 7/31/2019 Program Record c

    21/35

  • 7/31/2019 Program Record c

    22/35

    C Lab 22

    Department of Computer Science, Christ University

    Output:

  • 7/31/2019 Program Record c

    23/35

  • 7/31/2019 Program Record c

    24/35

    C Lab 24

    Department of Computer Science, Christ University

    printf("\nERROR !!!\nYou did not enter valid subscriber last name. Exiting ...\n\n");

    getch();return 1;

    }}

    stringconcat(str1,str2,dest) ;

    printf("\nConcantenated full name of subscriber is %s\n",dest);if(stringcompare(str1,str2)){

    printf("\nSubscriber first name and last name are SAME");

    }else

    {

    printf("\nSubscriber first name and last name are NOT SAME");

    }stringcpy(str1,str2);

    printf("\n\nFirst name %s stored in Last name (String 2) => %s",str1,str2);getch();return 0;

    }

    int stringcompare(char str1[],char str2[]){

    int i=0,flag=0;

    while(str1[i]!='\0' && str2[i]!='\0'){

    if(str1[i]!=str2[i]){flag=1;

    break;}

    i++;}

    if (flag==0 && str1[i]=='\0' && str2[i]=='\0')return 1;

    else

    return 0;

    }

    int stringlen(char s[])

    {int x;

    x=0;while (s[x] != '\0')

    {x=x+1;

    }x=x-1;

    return(x);}

    void stringcpy(char s1[],char s2[])

    {

    int x,len;

    len=strlen(s2);for (x=0; x

  • 7/31/2019 Program Record c

    25/35

    C Lab 25

    Department of Computer Science, Christ University

    void stringconcat(char s1[],char s2[],char s3[]){

    int i=0,j,l;strcpy(s3,s1);

    l=strlen(s1);

    s3[l++]=' ';

    while(s2[i]!= '\0')s3[l++]=s2[i++];s3[l]= '\0';

    }

    int validate_name(char s[])

    {

    int valid = 1,i;

    for (i = 0; i < strlen(s) - 1; i++){

    if (!isalpha(s[i])){

    valid = 0;

    break;}

    }return valid;

    }

  • 7/31/2019 Program Record c

    26/35

  • 7/31/2019 Program Record c

    27/35

    C Lab 27

    Department of Computer Science, Christ University

    Program Number : 9

    Program Name : Implementation of storage types

    Date Implemented : August 4, 2012

    ___________________________________________________________________________

    Program to demo storage classes using customer outstanding amounts

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include

    #define MAXNUM 3#define MAX_LEN 100

    void funct1(void);void funct2(void);

    int sum_up(void);int validate_number(char []);

    /* external variable, scope is global to main(), funct1() and funct2() */int GLOBALVAR = 10;

    int main()

    {

    printf("\n****STORAGE CLASSES AND SCOPE****\n");printf("\n****EXTERN AND AUTO STORAGE****\n");

    /* external variable */

    GLOBALVAR = 20;

    printf("\nVariable GLOBALVAR, in main() = %d\n", GLOBALVAR);funct1();

    printf("\nVariable GLOBALVAR, in main() = %d\n", GLOBALVAR);funct2();

    printf("\nVariable GLOBALVAR, in main() = %d\n", GLOBALVAR);

    /*Static example*/

    int count;

    printf("\n*****STATIC STORAGE*****\n");printf("Key in %d outstanding amounts of customer to be summed ", MAXNUM);

    for(count = 0; count < MAXNUM; count++){

    sum_up();

    }

    printf("\n*****COMPLETED*****\n");

    getch();

    return 0;}

    /* external variable, scope is global to funct1() and funct2() */int GLOBALVAR2 = 30;

    void funct1(void)

    {/* auto variable, scope local to funct1() and funct1() cannot access the external GLOBALVAR

    */

    char GLOBALVAR;

    /* local variable to funct1() */GLOBALVAR = 'A';

    /* external variable */

  • 7/31/2019 Program Record c

    28/35

    C Lab 28

    Department of Computer Science, Christ University

    GLOBALVAR2 = 40;

    printf("\nIn funct1(), GLOBALVAR = %c and GLOBALVAR2 = %d\n", GLOBALVAR,

    GLOBALVAR2);}

    void funct2(void)

    { /* auto variable, scope local to funct2(), and funct2() cannot access the external GLOBALVAR2*/

    double GLOBALVAR2;

    /* external variable */GLOBALVAR = 50;

    /* auto local variable to funct2() */

    GLOBALVAR2 = 1.234;

    printf("\nIn funct2(), GLOBALVAR = %d and GLOBALVAR2 = %.4f\n", GLOBALVAR,GLOBALVAR2);

    }int sum_up(void){

    /* at compile time, sum is initialized to 0 */static int sum = 0;

    int num;printf("\nEnter bill amount of customer to be summed : ");

    char temp[MAX_LEN];

    if(fgets(temp, MAX_LEN, stdin) != NULL){

    if (validate_number(temp)){

    num = atoi(temp);

    }else

    {printf("\nYou did not enter valid amount rounded to nearest whole number for

    customer.Skipping ...\n\n");getch();

    return 1;

    }

    }

    sum += num;printf("\nThe current total is: %d\n", sum);return 0;

    }

    int validate_number(char s[]){

    int valid = 1,i;for (i = 0; i < strlen(s) - 1; i++)

    {if (!isdigit(s[i]))

    {valid = 0;break;

    }

    }

    return valid;

    }

  • 7/31/2019 Program Record c

    29/35

    C Lab 29

    Department of Computer Science, Christ University

    Output:

  • 7/31/2019 Program Record c

    30/35

    C Lab 30

    Department of Computer Science, Christ University

    Program Number : 10

    Program Name : Demonstration of pointer operations

    Date Implemented : August 10, 2012

    ___________________________________________________________________________

    Program to demonstrate pointer operations on an array of customer call codes.

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include#define MAX_LEN 10

    int validate_number(char []);int main(){

    int custcallcode[MAX_LEN];int *ptrArr, *ptrArr1,i;

    printf("\nEnter %d customer call codes:\n\n",MAX_LEN);

    for ( i = 0; i

  • 7/31/2019 Program Record c

    31/35

    C Lab 31

    Department of Computer Science, Christ University

    ptrArr1 = &custcallcode[5];

    printf("\n\nSubtraction of two pointers ptrArr1 - ptrArr ( No. of elements between two pointer locations) : %d\n",ptrArr1 - ptrArr);

    getch();return 0;

    }

    int validate_number(char s[]){int valid = 1,i;

    for (i = 0; i < strlen(s) - 1; i++)

    {if (!isdigit(s[i]))

    {

    valid = 0;

    break;}

    }return valid;

    }

  • 7/31/2019 Program Record c

    32/35

    C Lab 32

    Department of Computer Science, Christ University

    Output:

  • 7/31/2019 Program Record c

    33/35

    C Lab 33

    Department of Computer Science, Christ University

    Program Number : 11

    Program Name : Demonstration of macro processing

    Date Implemented : August 26, 2012

    ___________________________________________________________________________

    Program to demonstrate macro processing using customer name and number and

    printing that records by macro.

    /***************************************************************

    * Author: Nisha Singh

    ***************************************************************/

    #include

    #define MAX_LEN 100 /* Single Line Macro*/

    /* Multi Line Macro*/

    # define getcustomernumber printf("Enter the Subscriber Mobile Number: "); \

    if(fgets(temp, MAX_LEN, stdin) != NULL) \{ \

    if (validate_number(temp)) \{ \

    num = atoi(temp); \

    } \else \

    { \printf("\nERROR !!!\nYou did not enter valid integer value.Exiting ...\n\n"); \

    getch(); \return 1; \

    } \

    }

    #define getcustomername printf("Enter the Subscriber Name: "); scanf("%s",&name); /* Single LineMacro*/

    #define printoutput printf("\nThe Subscriber Record is: "); printf("\t\nSubscriber Name: %s",name);printf("\t\nSubscriber Number: %d",num); /* Single Line Macro*/

    int validate_number(char []);

    int main(){

    int num;char name[MAX_LEN];

    char temp[MAX_LEN];

    getcustomernumber;getcustomername;

    printoutput;getch();

    return 0;

    }

    int validate_number(char s[]){

    int valid = 1,i;

    for (i = 0; i < strlen(s) - 1; i++)

    {if (!isdigit(s[i])){

    valid = 0;

  • 7/31/2019 Program Record c

    34/35

    C Lab 34

    Department of Computer Science, Christ University

    break;

    }}

    return valid;}

  • 7/31/2019 Program Record c

    35/35


Recommended