Wednesday, January 25, 2012

Assignment on Structure in C++

Q1. Define a structure for employee having the following fields

Name Char[30]

Empcode char[10]

Father’s name char[30]

Salary float;

Q2. Define a structure for CAR having the following fields

Model char[10]

CC int

Name Char[10]

Year of manuf. Int

Q3. Define a structure for STUDENT having the following fields

Student name char [20]

Roll no int

Father’s name char[20]

Class int

Section char

Q4. Define a structure for BOOK having the following fields

NAME

First name char[10]

Last name char[10]

Middle name char[10]

Pub_Address

Name char[10]

Place char [10]

BOOK

Access No integer

Title Char[30]

Pages integer

Publisher Pub_address

Author NAME

Q5. Find out the error(s) for the following code segment

Struct

{

short day;

short month;

short year;

}birth_date, joiing_date , retire_date;

Q6. Find out the error(s) for the following code segment

Struct First

{

int a;

float b;

}s1;

struct second

{

int a;

float b;

}s2;

s1.a = 10; s1.b=20;

s1 = s2;

Q7 Find out the error(s) in the following program segment

Struct time

{ int hrs, mins;

}

time t1;

Q8. Identify and discuss the error(s) in the following code segment

#include<iostream.h>

struct s1 {

int a;

float b;

char c;

} st1,st2,st3;

int main( )

{

struct s2 {

int x;

float y;

char z;

}ss1,ss2.ss3;

// read and initialize structure

ss2=ss1;

…….

…….

Ss3.z = st1.c;

……..

……

}

void func1( )

{

ss2.x = st1.a;

ss3.y = st2.b;

ss1.z = st3.c;

ss1 = ss3;

}

Q9. Give the output of the following program segment

#include<iostream.h>

struct point

{

int x, y;

};

void display( point P)

{

cout<<P.x <<” :”<<p.y<<endl;

}

void main( )

{

point U={20.40},V,W;

V = U;

V.x +=20;

W = V;

U.y +=10;

U.x +=5;

W.x -=5;

Display(U);

Display(V);

Display(W);

}

Q10. Declare and initialize an array of 5 students that store rollno, name and marks in 3 subjects for students.

Q11. Declare a structure to represent a student having the following fields NAME, ROLL NO , PHY, MATHS,

CHEMISTRY, ENGLISH , COMPUTER, TOTAL MARKS , GRADE. Also write a program to read the

fields NAME, ROLL NO, and marks obtained in PHYSICS, CHEMISTRY, MATHS,ENGLISH and

COMPUTER. Find out the total marks obtained by the student and his/her grade. The criteria for grade

calculation is as follows

Total marks Grade

>=450 A+

<450 and >=400 A

<400 and >= 350 B+

<350 and >= 300 B

<300 C

display the result on the screen.

Q12 Use the above data given on Q11 and expand the same for 10 student.

Q13. Declare a structure to represent a complex number ( a number having a real part and imaginary part). Write functions to add, subtract , multiply and divide two complex numbers.

No comments:

Post a Comment