Mcs Ignouassignmentguru 2017 2018

  • Uploaded by: khadija
  • 0
  • 0
  • August 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Mcs Ignouassignmentguru 2017 2018 as PDF for free.

More details

  • Words: 2,072
  • Pages: 11
SOLVED BY WWW.KHOJI.NET

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

MCS-011(Problem Solving and Programming) Solved Assignment for 2017-18

Solved by KHOJI.NET Assignment is completely solved by WWW.KHOJI.NET owner Ramanpreet Singh. No other can claim their rights on this assignment. Solve your own and don’t try to steal my work

WWW.KHOJI.NET WWW.KHOJINET.IN

WWW.FACEBOOK.COM/KHOJINET

LIKE OUR FACEBOOK PAGE

facebook.com/khojinet 31-Jul-17

for regular updates

SOLVED BY WWW.KHOJI.NET MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET Course Code : MCS-011 Course Title : Problem Solving and Programming Assignment Number

: BCA(2)/011/Assignment/17-18

Maximum Marks

: 100

Weightage

: 25%

Last Dates for Submission : 15th October, 2017 (For July 2017 Session) 15th April, 2018 (For January 2018 Session) Q.1. Draw a flow chart and write its corresponding C program to convert an octal number to its equivalent decimal number. Do it from book… 2. Write an algorithm and its corresponding C program to illustrate an ATM money withdrawl operation from user’s savings’ account. Solution: This C Program performs ATM transaction. The types of ATM transaction are 1) Balance checking 2) Cash withdrawal 3) Cash deposition. Here is C Program to display the ATM transaction: 1. #include <stdio.h> 2. 3. unsigned long amount=1000, deposit, withdraw; 4. int choice, pin, k; 5. char transaction ='y'; 6. 7. void main() 8. { 9. while (pin != 1520) 10. { 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.

printf("ENTER YOUR SECRET PIN NUMBER:"); scanf("%d", &pin); if (pin != 1520) printf("PLEASE ENTER VALID PASSWORD\n"); } do {

LIKE OUR FACEBOOK PAGE

printf("********Welcome to ATM Service**************\n"); printf("1. Check Balance\n"); printf("2. Withdraw Cash\n");

facebook.com/khojinet

for regular updates

SOLVED BY WWW.KHOJI.NET

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

21. 22. 23. 24.

printf("3. Deposit Cash\n"); printf("4. Quit\n"); printf("******************?**************************?*\n\n"); printf("Enter your choice: ");

25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36.

scanf("%d", &choice); switch (choice) { case 1: printf("\n YOUR BALANCE IN Rs : %lu ", amount); break; case 2: printf("\n ENTER THE AMOUNT TO WITHDRAW: "); scanf("%lu", &withdraw); if (withdraw % 100 != 0) { printf("\n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100") ;

37.

}

38. 39.

else if (withdraw >(amount - 500)) {

40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65.

LIKE OUR FACEBOOK PAGE

printf("\n INSUFFICENT BALANCE"); } else { amount = amount - withdraw; printf("\n\n PLEASE COLLECT CASH"); printf("\n YOUR CURRENT BALANCE IS%lu", amount); } break; case 3: printf("\n ENTER THE AMOUNT TO DEPOSIT"); scanf("%lu", &deposit); amount = amount + deposit; printf("YOUR BALANCE IS %lu", amount); break; case 4: printf("\n THANK U USING ATM"); break; default: printf("\n INVALID CHOICE"); } printf("\n\n\n DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): \n"); fflush(stdin); scanf("%c", &transaction); if (transaction == 'n'|| transaction == 'N') k = 1;

facebook.com/khojinet

for regular updates

SOLVED BY WWW.KHOJI.NET 66. 67. 68. }

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

} while (!k); printf("\n\n THANKS FOR USING OUT ATM SERVICE");

Q.3. Write a program to find the largest element in an array using Recursion. Solution: Write a program to find the largest element in an array using Recursion Here is the source code of the C program to print the largest number in an unsorted array: 1. #include <stdio.h> 2. 3. int large(int[], int, int); 4. 5. int main() 6. { 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17.

int size; int largest; int list[20]; int i; printf("Enter size of the list:"); scanf("%d", &size); printf("Printing the list:\n"); for (i = 0; i < size ; i++) { list[i] = rand() % size;

18. 19.

}

20. 21.

if (size == 0) {

22. 23. 24. 25. 26. 27. 28. 29. 30. } 31. int 32. { 33. 34. 35. 36.

printf("%d\t", list[i]);

printf("Empty list\n"); } else { largest = list[0]; largest = large(list, size - 1, largest); printf("\nThe largest number in the list is: %d\n", largest); } large(int list[], int size, int largest) if (size == 1) return largest; if (size > -1)

LIKE OUR FACEBOOK PAGE

facebook.com/khojinet

for regular updates

SOLVED BY WWW.KHOJI.NET 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. }

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

{ if (list[size] > largest) { largest = list[size]; } return(largest = large(list, size - 1, largest)); } else { return largest; }

Q.4. Write a C program to separate even and odd numbers of an array and put them in two arrays. Solution: This C Program puts even & odd elements of an array in 2 separate arrays. The program first finds the odd and even elements of the array. Then the odd elements of an array are stored in one array and even elements of an array are stored in another array. 1. #include <stdio.h> 2. 3. void main() 4. { 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25.

long int ARR[10], OAR[10], EAR[10]; int i, j = 0, k = 0, n; printf("Enter the size of array AR \n"); scanf("%d", &n); printf("Enter the elements of the array \n"); for (i = 0; i < n; i++) { scanf("%ld", &ARR[i]); fflush(stdin); } /* Copy odd and even elements into their respective arrays */ for (i = 0; i < n; i++) { if (ARR[i] % 2 == 0) { EAR[j] = ARR[i]; j++; } else {

LIKE OUR FACEBOOK PAGE

facebook.com/khojinet

for regular updates

SOLVED BY WWW.KHOJI.NET 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. }

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

OAR[k] = ARR[i]; k++; } } printf("The elements of OAR are \n"); for (i = 0; i < j; i++) { printf("%ld\n", OAR[i]); } printf("The elements of EAR are \n"); for (i = 0; i < k; i++) { printf("%ld\n", EAR[i]); }

Q.3. Write a C program to determine a given matrix is a sparse matrix. Solution: This C Program determines the given matrix is a sparse matrix. Sparse matrix is a matrix with the majority of its elements equal to zero. This program accepts matrix and checks whether the given matrix is a sparse matrix. 1. #include <stdio.h> 2. 3. void main () 4. { 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

static int array[10][10]; int i, j, m, n; int counter = 0; printf("Enter the order of the matix \n"); scanf("%d %d", &m, &n); printf("Enter the co-efficients of the matix \n"); for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j)

15. 16. 17. 18. 19. 20.

{

21. 22. 23. 24. 25.

}

scanf("%d", &array[i][j]); if (array[i][j] == 0) { ++counter; } } if (counter > ((m * n) / 2)) { printf("The given matrix is sparse matrix \n");

LIKE OUR FACEBOOK PAGE

facebook.com/khojinet

for regular updates

SOLVED BY WWW.KHOJI.NET 26. 27. 28. 29.

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

} else printf("The given matrix is not a sparse matrix \n"); printf("There are %d number of zeros", counter);

30. }

Q.6. Write an interactive C program to calculate the sum of array elements using pointer. Solution: This C Program calculates the sum of array elements using pointer. The program uses the pointer to traverse the array and adds up the element values there. 1. #include <stdio.h> 2. #include <malloc.h> 3. 4. void main() 5. { 6.

int i, n, sum = 0;

7. 8.

int *a;

9. 10. 11. 12. 13. 14.

printf("Enter the size of array A \n"); scanf("%d", &n); a = (int *) malloc(n * sizeof(int)); printf("Enter Elements of First List \n"); for (i = 0; i < n; i++) {

15. 16. 17. 18. 19. 20. 21. 22. 23. }

scanf("%d", a + i); }
Q.7. Write an interactive C program to append the contents of a file at the end of another file without using any builtin functions. Solution: This C Program appends the content of file at the end of another. 1. #include <stdio.h> 2. #include <stdlib.h> 3. 4. main() 5. {

LIKE OUR FACEBOOK PAGE

facebook.com/khojinet

for regular updates

SOLVED BY WWW.KHOJI.NET 6. 7. 8. 9.

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

FILE *fsring1, *fsring2, *ftemp; char ch, file1[20], file2[20], file3[20]; printf("Enter name of first file ");

10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21.

gets(file1); printf("Enter name of second file "); gets(file2); printf("Enter name to store merged file "); gets(file3); fsring1 = fopen(file1, "r"); fsring2 = fopen(file2, "r"); if (fsring1 == NULL || fsring2 == NULL) { perror("Error has occured"); printf("Press any key to exit...\n"); exit(EXIT_FAILURE);

22. 23.

} ftemp = fopen(file3, "w");

24. 25.

if (ftemp == NULL) {

26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. }

perror("Error has occures"); printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } while ((ch = fgetc(fsring1)) != EOF) fputc(ch, ftemp); while ((ch = fgetc(fsring2) ) != EOF) fputc(ch, ftemp); printf("Two files merged %s successfully.\n", file3); fclose(fsring1); fclose(fsring2); fclose(ftemp); return 0;

Q.8. Write an interactive C program to create a file containing student’s records and also give a provision to update/modify the records too. Solution: This C Program creates student record and updates it. 1. /* 2. * C Program to Create Student Record and Update it 3. */ 4. #include <stdio.h> 5. #include <stdlib.h> 6. #include <string.h>

LIKE OUR FACEBOOK PAGE

facebook.com/khojinet

for regular updates

SOLVED BY WWW.KHOJI.NET

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

7. #define size 200 8. 9. struct std 10. { 11. int id; 12. char *name; 13. }*std1, *std3; 14. 15. void display(); 16. void create(); 17. void update(); 18. 19. FILE *fp, *fp1; 20. int count = 0; 21. 22. void main(int argc, char **argv) 23. { 24.

int i, n, ch;

25. 26.

printf("1] Create a Record\n");

27. 28. 29. 30. 31. 32. 33. 34. 35. 36.

printf("2] Display Records\n"); printf("3] Update Records\n"); printf("4] Exit"); while (1) { printf("\nEnter your choice : "); scanf("%d", &ch); switch (ch) { case 1:

37. 38. 39. 40. 41. 42.

fp = fopen(argv[1], "a"); create(); break; case 2: fp1 = fopen(argv[1],"rb"); display();

43. 44. 45. 46. 47. 48. 49. 50. 51. 52. }

break; case 3: fp1 = fopen(argv[1], "r+"); update(); break; case 4: exit(0); } }

LIKE OUR FACEBOOK PAGE

facebook.com/khojinet

for regular updates

SOLVED BY WWW.KHOJI.NET

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

53. 54. /* To create an student record */ 55. void create() 56. { 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68.

int i; char *p;

69. 70. }

fclose(fp);

std1 = (struct std *)malloc(sizeof(struct std)); std1->name = (char *)malloc((size)*(sizeof(char))); printf("Enter name of student : "); scanf(" %[^\n]s", std1->name); printf("Enter student id : "); scanf(" %d", &std1->id); fwrite(&std1->id, sizeof(std1->id), 1, fp); fwrite(std1->name, size, 1, fp); count++; // count to number of entries of records

71. 72. /* Display the records in the file */ 73. void display() 74. { 75. std3=(struct std *)malloc(1*sizeof(struct std)); 76. std3->name=(char *)malloc(size*sizeof(char)); 77. int i = 1; 78. 79. if (fp1 == NULL) 80. printf("\nFile not opened for reading"); 81. while (i <= count) 82. { 83. 84. 85. 86. 87. 88.

fread(&std3->id, sizeof(std3->id), 1, fp1); fread(std3->name, size, 1, fp1); printf("\n%d %s",std3->id,std3->name); i++; } fclose(fp1);

89. free(std3->name); 90. free(std3); 91. } 92. 93. void update() 94. { 95. int id, flag = 0, i = 1; 96. char s[size]; 97. 98. if (fp1 == NULL)

LIKE OUR FACEBOOK PAGE

facebook.com/khojinet

for regular updates

SOLVED BY WWW.KHOJI.NET 99. 100. 101. 102.

MSC-011 SOLVED ASSIGNMENT BY KHOJI.NET

{ printf("File cant be opened"); return; }

103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114.

printf("Enter Student id to update : "); scanf("%d", &id); std3 = (struct std *)malloc(1*sizeof(struct std)); std3->name=(char *)malloc(size*sizeof(char)); while(i<=count) { fread(&std3->id, sizeof(std3->id), 1, fp1); fread(std3->name,size,1,fp1); if (id == std3->id) { printf("Enter new name of Student to update : "); scanf(" %[^\n]s", s);

115. 116.

fseek(fp1, -204L, SEEK_CUR); fwrite(&std3->id, sizeof(std3->id), 1, fp1);

117. 118.

fwrite(s, size, 1, fp1); flag = 1;

119. 120. 121. 122. 123. 124. 125. 126. 127. 128.

break;

129. 130. 131.

} i++; } if (flag != 1) { printf("No Student record found"); flag = 0; } fclose(fp1); free(std3->name); free(std3);

/* to free allocated memory */

}

LIKE OUR FACEBOOK PAGE

facebook.com/khojinet

for regular updates

Related Documents

Mcs
June 2020 14
Rkpd-2017-2018.pdf
December 2019 22
Gem 2017-2018 Final.docx
April 2020 21
Raei 2017-2018.pdf
May 2020 8

More Documents from ""