Question

In: Computer Science

Q1: Constraint: Use concept of dynamic allocation for implementation Statement: In a class there are N...

Q1: Constraint:
Use concept of dynamic allocation for implementation


Statement:
In a class there are N students. All of them have appeared for the test. The teacher evaluated
the test and noted marks according to their roll numbers. Marks of each students has to be incremented
by 5. Print list of marks of students before and after increment.

Solutions

Expert Solution

Dynamic memory allocation is a feature provided during the run time of the program. In dynamic memory allocation the data are stored in the heap memory. In dynamic memory allocation for allocating a variable value we are using pointers. For this dynamic memory allocation there are some functions. These functions are:

  • Malloc (): In malloc () we are allocating the specific number of bytes for a memory.
  • Calloc (): In calloc () we are allocating the memory and initializing the memory as zero.
  • Reaclloc (): In this we are reallocating the memory there by we can increase and decrease the size of the memory.
  • Free: Here we can release the memory which has been allocated.

Since in the above question the language is not specific. I have used C language for the compliation of the code. I am attaching the code along with the screenshot of both input and output.

PROGRAM CODE :

#include <stdio.h>
#include<stdlib.h>

int main()
{
    int *arr;
    int N,i;
    int *new_array;
    
    printf(" Enter total number of students details wanted to be input :");
    scanf("%d",&N);
    
    /* allocation of memory dynamically */
    arr = (int*)malloc(N*sizeof(int));

    if(arr==NULL)
    {
        printf(" Insufficient Memory...\n");
        return 0;
    }
    printf(" Enter %d the marks of the students : \n ",N);
    for(i=0;i<N;i++)
    {
        scanf("%d",(arr+i));
               
    }
    
    printf("\n");
    printf("MARK OF STUDENTS BEFORE INCREMENTING\n");
    printf("------------------------------------\n");
    for(i=0;i<N;i++)
    {
        
        printf("The student of Roll Number %d has %d marks \n",i+1,(*(arr+i)));
    }
    
    printf("\n");
    printf("\n");
    printf("MARK OF STUDENTS AFTER INCREMENTING\n");
    printf("-----------------------------------\n");
    for(i=0;i<N;i++)
    {
        
        printf("The student of Roll Number %d has %d marks \n",i+1,(*(arr+i)+5));
    }
    return 0;
}

SCREENSHOT OF INPUT

SCREENSHOT OF OUTPUT


Related Solutions

In the following keypad notation Use a class and dynamic allocation of a pointer variable to...
In the following keypad notation Use a class and dynamic allocation of a pointer variable to enter the digit code of the following text input MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY Use an inherited class using pointer variable to output the phone number from the following text input 1-800-COMCAST 1-800-VERIZON 1-800-BANCORP 1-800-MYKOHLS 1-800-JCPENNY Write C++ code and pseudocode in a doc file A computer key board has defect (like speech defect in humans) in reading for ‘p’ /’P’ as...
In the following keypad notation Use a class and dynamic allocation of a pointer variable to...
In the following keypad notation Use a class and dynamic allocation of a pointer variable to enter the digit code of the following text input MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY Use an inherited class using pointer variable to output the phone number from the following text input 1-800-COMCAST 1-800-VERIZON 1-800-BANCORP 1-800-MYKOHLS 1-800-JCPENNY Write C++ code and pseudocode in a doc file A computer key board has defect (like speech defect in humans) in reading for ‘p’ /’P’ as...
This assignment introduces the concept of dynamic memory allocation, destructors, copy constructors, and overloading the assignment...
This assignment introduces the concept of dynamic memory allocation, destructors, copy constructors, and overloading the assignment operator, , and also provides some insight into how the C++ string class works. Assignment In this assignment, you will create a class to represent a string of characters. You can think of this class as a simplified version of the C++ string class. Program You will need to write one class for this assignment. A main program to test your class has been...
Using C++ Use dynamic allocation and functions (using pointer variables only) to read the names from...
Using C++ Use dynamic allocation and functions (using pointer variables only) to read the names from the .txt file and sort the names in lexical order Grumpy Dopey Doc Happy Bashful Sneezy Sleepy
In the assignment you will use the vector class tomanage a dynamic array.After completing this assignmentyou...
In the assignment you will use the vector class tomanage a dynamic array.After completing this assignmentyou will be able to • use thevector classto implement programs; • using iteratorsto morethrough a vector; • use pointers to a vector; • use member functions of thevector class. Assignment Description: Call your driver "vector_test_driver.cpp", your classdeclaration file “vlist.h” and your class implementation file "vlist.cpp". Define the following behavior for vlist 1. Implement a default constructor. Include the followingmessage, "Default Constructor Invoked" every time...
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files....
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header. Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard > Course Content > Classes and Objects > Demo Program 2: class Rectangle in three files. In this lab, we will use class inheritance to write a...
Problem Statement: Implement the MyString class using a header and implementation file named MyString.h and MyString.cpp...
Problem Statement: Implement the MyString class using a header and implementation file named MyString.h and MyString.cpp respectively. Make sure to properly test your code on your own by creating a test driver that tests every function created in the MyString class. Deliverables: proj3-MyString.h proj3-MyString.cpp proj3-testMain.cpp Memory Requirements: Your MyString should start with 10 bytes of allocated memory and should grow in size by doubling. So, we should be able to predict the capacity of your MyString as acquiring a patten...
Use this implementation of Integer node, public class IntegerNode { public int item; public IntegerNode next;...
Use this implementation of Integer node, public class IntegerNode { public int item; public IntegerNode next; public IntegerNode(int newItem) { item = newItem; next = null; } // end constructor public IntegerNode(int newItem, IntegerNode nextNode) { item = newItem; next = nextNode; } // end constructor } // end class IntegerNode You need to implement add( ), delete( ), traverse( ) methods for an ordered linked list. And after insertion and deletion, your linked list will remain ordered. Your code...
Use the economic concept of scarcity to evaluate this statement: "College education should be free for...
Use the economic concept of scarcity to evaluate this statement: "College education should be free for everyone." What would it mean to provide "free" college education to everyone?
Q1(using graph(s) and words )Use the economic theories to determine whether the statement in each of...
Q1(using graph(s) and words )Use the economic theories to determine whether the statement in each of the following question is True, False or Uncertain. Please explain using both words and graph(s) and make it concise. Your answer should be around ¾ to 1 page for the question. Consider a dam which provides drinking water for a local community and which allows free access to all. As a public good the only way to manage this resource is through government regulation...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT