World Top Softwares
Login Please

Join the forum, it's quick and easy

World Top Softwares
Login Please
World Top Softwares
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 


Rechercher Advanced Search

Log in

I forgot my password

Latest topics
» Practically as cut-price as files
3rd lab of 2nd semister EmptyMon Aug 01, 2011 11:44 pm by Guest

» Netbook Brands
3rd lab of 2nd semister EmptyMon Aug 01, 2011 5:39 am by Guest

» backlinks checker backlink service
3rd lab of 2nd semister EmptySun Jul 31, 2011 8:56 am by Guest

» how to buy facebook fans f4
3rd lab of 2nd semister EmptySat Jul 30, 2011 2:34 pm by Guest

» Alle bijzondere dingen in de zaanstreek
3rd lab of 2nd semister EmptySat Jul 30, 2011 8:11 am by Guest

» HERE YOU CAN POST ALL WEBSITE LINKS...
3rd lab of 2nd semister EmptyWed Aug 26, 2009 2:16 pm by onesimpletech

» cool web site for all must check it
3rd lab of 2nd semister EmptyMon Jul 06, 2009 2:32 pm by Snopy Cobra

» poetry spirit
3rd lab of 2nd semister EmptyMon Jul 06, 2009 2:31 pm by Snopy Cobra

» best to learn VC++
3rd lab of 2nd semister EmptySun May 10, 2009 3:22 pm by Guest

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search
Statistics
We have 30 registered users
The newest registered user is deigavr

Our users have posted a total of 191 messages in 126 subjects
Who is online?
In total there is 1 user online :: 0 Registered, 0 Hidden and 1 Guest

None

[ View the whole list ]


Most users ever online was 125 on Wed Apr 07, 2021 9:18 am
RSS feeds


Yahoo! 
MSN 
AOL 
Netvibes 
Bloglines 



3rd lab of 2nd semister

Go down

3rd lab of 2nd semister Empty 3rd lab of 2nd semister

Post by Snopy Cobra Wed Feb 11, 2009 5:51 am

Lab # 3

Objective

Understanding the use of Structures, classes & constructors.


Theory

Strictures
“A structure is a collection of variables under a single name.”
We have seen how simple variable can hold one piece of information at a time and how arrays can hold a number of pieces of information of the same data type. These two data storage mechanisms can handle a great variety of situations. But we often want to operate on data items of different types together as a unit. In this case, neither the variable nor the array is adequate. So it is convenient to use Structure in programming languages.
The variables used in structure can be of different types, and each has a name which is used to select it from the structure. A structure is a convenient way of grouping several pieces of related information together. A structure can be defined as a new named type, thus extending the number of available types. It can use other structures, arrays or pointers as some of its members, though this can get complicated unless you are careful.

A structure type is defined by

struct struct-name {
type field-name;
type field-name;
...
}

Classes


Defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features). A class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program.


Constructors


Constructors are a new concept for people doing structured programming. Constructors do not normally exist in non-OO languages such as C and Basic. Earlier we spoke about special methods that are used to construct objects. In Java, C# and C++, as well as in other Object Oriented languages, constructors are methods that share the same name as the class and have no return type. Note again that a constructor does not have a return value, if you provide a return value, the compiler will not treat the method as a constructor.


Task

1. Write a program that maintains a Bio data of 5 persons, using Structures.

[The record includes the Name, Father’s Name, Age, NIC # etc]

2. Write a program that accepts the name, age, and basic salary from the user into a Structure. Write a Display function in the Structure to display the data accepted.

3. Create a class containing integer as its field. The class should have 2 constructors, one should initialize the field to 10 and another should take in an integer parameter and initialize the field to that parameter value. The class should also contain a method that displays the value of the field.

4. Write a program that defines a Sphere class with three constructors. The first accepts no arguments. It assumes the sphere is centered at the origin and has a radius of one unit. The second accepts one double value that represents the radius of the sphere. It assumes the sphere is centered at the origin. The third accepts four double arguments. These specify the coordinates of the center and the radius.
Snopy Cobra
Snopy Cobra
Admin
Admin

Number of posts : 99
Age : 34
Location : Bahria University Karachi
Reputation : 0
Registration date : 2008-07-31

https://telecompk.forumotion.com

Back to top Go down

3rd lab of 2nd semister Empty Re: 3rd lab of 2nd semister

Post by Snopy Cobra Tue Feb 17, 2009 11:21 am

1. Write a program that maintains a Bio data of 5 persons, using Structures.

[The record includes the Name, Father’s Name, Age, NIC # etc]

#include
void main(void)
{
 struct data
 {
  /*1. Write a program that maintains a Bio data of 5 persons, using Structures.

[The record includes the Name, Father’s Name, Age, NIC # etc]*/
  char name[15];
  char father[15];
  int age;
  int nic;
 }dataa[5];
 int i;
  for(i=0;i<=4;i++)
  {
  printf("ENTER YOUR NAME\n");
  scanf("%s",&dataa[i].name);
  printf("ENTER FATHER NAME\n");
  scanf("%s",&dataa[i].father);
  printf("ENTER AGE\n");
  scanf("%d",&dataa[i].age);
  printf("ENTER NIC\n");
  scanf("%d",&dataa[i].nic);
   
  }
}
Snopy Cobra
Snopy Cobra
Admin
Admin

Number of posts : 99
Age : 34
Location : Bahria University Karachi
Reputation : 0
Registration date : 2008-07-31

https://telecompk.forumotion.com

Back to top Go down

3rd lab of 2nd semister Empty Re: 3rd lab of 2nd semister

Post by Snopy Cobra Tue Feb 17, 2009 11:51 am

#include
void main(void)
{
 struct data
 {
  /*2. Write a program that accepts the name, age, and basic salary from the user into a Structure. 
  Write a Display function in the Structure to display the data accepted.*/

  char name[15];
  int age;
  int sal;
 }dataa;
  {
  printf("ENTER YOUR NAME\n");
  scanf("%s",&dataa.name);
  printf("ENTER AGE");
  scanf("%d",&dataa.age);
  printf("ENTER SALERY");
  scanf("%d",&dataa.sal);
  }
printf("\nYOUR NAME %s",dataa.name);
printf("\nYOUR AGE %d ",dataa.age);
printf("\nYOUR SALERY %d \n ",dataa.sal);
}
Snopy Cobra
Snopy Cobra
Admin
Admin

Number of posts : 99
Age : 34
Location : Bahria University Karachi
Reputation : 0
Registration date : 2008-07-31

https://telecompk.forumotion.com

Back to top Go down

3rd lab of 2nd semister Empty Re: 3rd lab of 2nd semister

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum