Assignments - XII Computer Science

POINTERS ASSIGNMENT
Assignment Date: 09/09/15
Submission Date: 14/09/15

Q1. What will be the output of the following program:

int main()
{
int x [ ] = { 50, 40, 30, 20, 10}:
int *p, *t;
p = x;
t = x + 1;
cout << *p << “,” << *t++;
return 0;
}

Q2. What will be the output of the program( Assume all necessary header files are included)

void print (char * p )
{
p = "Comp";
cout<<"value is "<<p<<endl;
}
int main( )
{
char * x = "Class XII";
print(x);
cout<<"new value is "<<x<<endl;
return 0;
}

Q3. Identify errors on the following code segment, and underline the error.

float c[ ] ={ 1.2,2.2,3.2,56.2};
float *k,*g;
k=c;
g=k+4;
k=k*2;
g=g/2;
cout<<”*k=”<<*k<<”*g=”<<*g;

Q4. Write the output of the following program.

void print (char * p )
{
p = "Comp";
cout<<"value is "<<p<<endl;
}
int main( )
{
char * x = "Class XII";
print(x);
cout<<"new value is "<<x<<endl;
return 0;
}

Q5. Predict the output of the following code:
# include<iostream.h>

int main()
{
int arr[] = {12, 23, 34, 45};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = *ptr++; cout << val << endl;
val = *ptr; cout << val << endl;
val = *++ptr; cout << val << endl;
return 0;
}

Q6. What will be the output of the following program?
#include<iostream.h>
#include<ctype.h>
#include<string.h>

void changestring(char text[], int &counter)
{
char *ptr = text;
int length=strlen(text);
for(;counter<length-2;counter+=2, ptr++)
{
*(ptr+counter) = tolower(*(ptr+counter));
}
}

int main()
{                                                                                          
int position = 0;
char message[]= “POINTERS FUN”;
changestring(message, position);
cout<<message<< “@” <<position;
return 0;
}

Q7. Why does an array always start with index 0 in C++?

Q8. What is “this” pointer? Give an example to illustrate the use of it in C++.

Q9. Write a program to illustrate the use of structure pointers.

Q10. Distinguish between
                int *ptr = new int(5);                                      //Statement 1
                Int *ptr = new int[5];                                      //Statement 2

Q11.Write a program in C++ to calculate the row sum and column sum of a 2-D array using pointers (i.e. Dynamic Memory Allocation).

Q12. Write a program to exchange the positions of strings stored in array using array of pointers.

Q13. Identify the errors, if any in the following program. Also give reasons for errors.
int main()
{
const int i=2;
const int* const ptr = &i;
*ptr++;
int j =15;
ptr = &j;
return 0;
}


-------------------------------------------------------------------------------

Data File Handling Assignment
Assignment Date: 07/09/15
Submission Date: 11/09/15
Q1. Write a program to copy the content of a file “INPUT.TXT” into another file “OUTPUT.TXT”.
Q2. Write a function in C++ to count the number of lowercase alphabets present in a text file “BOOK.TXT”.
Q3. Write a function to modify a record in binary file “COLONY.DAT” using structure concept.
Q4. Write a function in C++ to count the number of lines present in a text file “STORY.TXT”.
Q5. Write a function in C++ to search for a BookNo from a binary file “BOOK.DAT”, assuming that the binary file is containing the objects of the following class:
                class {
                                int  BookNo;
                                char Title[20];
                public:
                                int RBno( ){ return BookNo; }
                                void Enter( ){ cin>>BookNo;    gets(Title); }
                                void Display( ){ cout<< BookNo<<Title<<endl;}
                };

Q6. Write a function in C++ to add new objects at the bottom of a binary file “STUDENT.DAT”, assuming the binary file is containing the objects of the following class.
class STUD{
int Rno;
char Name[20];
public:
void Enter(){  cin>>Rno;                gets(Name);}
void Display(){cout<<Rno<<Name<<endl;}
};

Q7. Observe the program segment carefully and answer the question that follows:
class item
{
int item_no;
char item_name[20];
public:
void enterDetail( );
void showDetail( );
int getItem_no( ){ return item_no;}
};
void modify(item x, int y )
{
fstream File;
File.open( “item.dat”, ios::binary | ios::in | ios::out) ;
item i;
int recordsRead = 0, found = 0;
while(!found && File.read((char*) &i , sizeof (i)))
{
recordsRead++;
if(i . getItem_no( ) = = y )
{
_________________________//Missing statement
File.write((char*) &x , sizeof (x));
found = 1;
}
}
if(! found)
cout<<”Record for modification does not exist” ;
File.close() ;
}
If the function modify( ) is supposed to modify a record in the file “ item.dat “,which item_no is y, with the values of item x passed as argument, write theappropriate statement for the missing statement using seekp( ) or seekg( ),whichever is needed, in the above code that would write the modified record at its proper place.
Q8. Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using seekp() and seekg() functions for performing the required task.
#include <fstream.h>
class Item
{
int Ino;char Item[20];
public:
//Function to search and display the content from a particular record number
void Search(int );
//Function to modify the content of a particular record number
void Modify(int);
};
void Item::Search(int RecNo)
{
fstream File;
File.open("STOCK.DAT",ios::binary| ios::in);
______________________ //Statement 1
File.read((char*)this,sizeof(Item));
cout<<Ino<<"==>"<<Item<<endl;
File.close();
}
void Item::Modify(int RecNo)
{
fstream File;
File.open("STOCK.DAT",ios::binary|ios::in|ios::out);
cout>>Ino;
cin.getline(Item,20);
______________________ //Statement 2
File.write((char*)this,sizeof(Item));
File.close();
}

Popular posts from this blog

Project Work for Class XII Informatics Practices (065) - CBSE 2020-2021