Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
CPP All : Structures passing/returning
Concept Learning Code Sheets

Passing Structure variables to a function #2955

Demonstration of how structure variables can be passed to function as pass-by-value or as pass-by-reference method

Passing structure to a function pass-by-value #2969

A program to demonstrate passing of structure to a function using pass by value method,

Structure passed as a reference #2979

A program to demonstrate how an structure is passed as a reference argument to a function.


Solved Problems

Slope of line -using structure Point passed to a function #2973

Write a program by declaring a structure Point with two integer values for i

Write a program by declaring a structure Point with two integer values for its position x and y. Now write a function that finds slope of a line drawn out of two points that are passed as structure argument to this function. Show implementation of this function and structure in the main routine assuming suitable values of x and y being initialised for two points.

Output Writing Structure pass by value/reference #2984

Write the output of the following program depicting structure instances being

Write the output of the following program depicting structure instances being called as value and called as reference to a function.

struct Sale {int ID; float value;};
void sc(Sale a,Sale &b)
{
a.ID=a.ID+1;
a.value=a.value+100;
b=a;
}
int main()
{
  Sale zone1={1,400.50},zone2;
  sc(zone1,zone2);
  cout<<"Zone 1 (ID, value) = "<<zone1.ID<<", "<<zone1.value<<endl;
  cout<<"Zone 2 (ID, value) = "<<zone2.ID<<", "<<zone2.value<<endl;
  return 0;
}

Output Writing – Pixel structure passed by reference #2987

Write down the output of the program and give steps in arriving at such outpu

Write down the output of the program and give steps in arriving at such output.

struct Pix {int x,y;};
void show(Pix &p)
{
  cout<<p.x++<<","<<++p.y<<endl;
}
int main()
{
  Pix P={50,60},Q,R;
  R=P;
  show(R);
  P.x+=10;P.y+=30;
  Q=R;
  show(P); show(Q); show(R);
  return 0;
}

 

Output Writing – Three dimensions in structure passed by reference #5596

Write down the output of the program.

struct three_d{int x,y,z;};

Write down the output of the program.

struct three_d{int x,y,z;};

void movein(three_d &t,int step=1) 
{ 
  t.x+=step; t.y-=step; t.z+=step;
} 
void moveout(three_d &t,int step=2) 
{ 
  t.x-=step; t.y+=step; t.z-=step;
} 

int main()
{
  three_d t1={10,20,5},t2={30,10,40};
  movein(t1);
  moveout(t2,5);
  cout<<t1.x<<","<<t1.y<<","<<t1.z<<endl;
  cout<<t2.x<<","<<t2.y<<","<<t2.z<<endl;  
  movein(t2,10);
  cout<<t2.x<<","<<t2.y<<","<<t2.z<<endl;  
  return 0;
}


Array of Structure – Output Writing #7663

Find and write the output of the following C++ program code:
Note: Assu

Find and write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.

struct Score { 
  int Year;float Topper; 
}; 
void change(Score *s,int x=10)
{
  s->Topper=(s->Topper+15)-x;
  s->Year++;
}	 
int main() 
{ 
  Score Arr[]={{2006,100},{2007,85}};
  Score *point=Arr;
  change(point,40);
  cout<<Arr[0].Year<<'#'<<Arr[0].Topper<<endl;
  change(++point);
  cout<<Year<<'#'<<Topper<<endl;
  return 0; 
}



Code Sheets:3  Solved Problems:5 
×
Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues


Back