Showing posts with label programs. Show all posts
Showing posts with label programs. Show all posts

C++ program to illustrate passing of structures by value.

Sunday, August 12, 2012


Write a C++ program to illustrate passing of structures by value. 

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct distance{
 int feet;
 int inches;
};
int main()
{
clrscr();
    distance length1, length2;
void prnsum(distance l1, distance l2);
cout<<"\n"<<"Enter length 1:\n";
cout<<"\n"<<"Feet:\n";
cin>>length1.feet;
cout<<"\n"<<"Inches:\n";
cin>>length1.inches;
cout<<"\n"<<"\n"<<"Enter length 2:\n";
cout<<"\n"<<"Feet:\n";
cin>>length2.feet;
cout<<"\n"<<"Inches\n";
cin>>length2.inches;
prnsum(length1, length2);
return 0;
}
void prnsum(distance  l1, distance l2)
{
  distance l3;
  l3.feet = l1.feet + l2.feet + (l1.inches +l2.inches)/12;
  l3.inches =( l1.inches + l2.inches)%12;
  cout<<"\n"<<"\n";
  cout<<"\n"<<"Total Feet:"<<l3.feet<<"\n";
  cout<<"\n"<<"Total Inches:"<<l3.inches;
  return;
}
/*
OUTPUT
------

Enter length 1:

Feet:
10

Inches:
1

Enter length 2:

Feet:
12

Inches
2

Total Feet:22

Total Inches:3


*/

C++ Program

Wednesday, August 1, 2012


Write a C++ Program to store information of 10 employees and to display information of an 
employee depending upon the employee no.


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct addr
{
int houseno;
char area[30];
char city[30];
char state[30];
};
struct emp
{
int empno;
char name[30];
char desig[30];
addr address;
float basic;
}worker;
emp sales_emp[10];
void display(int a);
void enter(void);
int main()
{
clrscr();
int eno,i;
char ch;
enter();
do
{
cout<<"\n Enter the employee no. whose information is to be displayed:";
cin>>eno;
int flag=0;
for(i=0;i<2;i++)
{
if(sales_emp[i].empno==eno)
{
display(i);
flag=1;
break;
}
}
if(!flag)
{
cout<<"\n sorry! no such employee found";
}
cout<<"\n display more...(y/n)\n";
cin>>ch;
}while(ch=='y');
getch();
return 0;
}
void enter(void)
{
for(int i=0;i<2;i++)
{
cout<<"\n employee no:";
cin>>sales_emp[i].empno;
cout<<"\n name:";
gets(sales_emp[i].name);
cout<<"\n designation:";
gets(sales_emp[i].desig);
cout<<"\n * address *";
cout<<"\n house no:";
cin>>sales_emp[i].address.houseno;
cout<<"\n area:";
gets(sales_emp[i].address.area);
cout<<"\n city:";
gets(sales_emp[i].address.city);
cout<<"\n state:";
gets(sales_emp[i].address.state);
cout<<"\n basic pay:";
cin>>sales_emp[i].basic;
cout<<"\n\n";
}
return;
}
void display(int a)
{
cout<<"\n employee data";
cout<<"\n enployee no.:"<<sales_emp[a].empno;
cout<<"\n name:";
cout.write(sales_emp[a].name,30);
cout<<"\n designation:";
cout.write(sales_emp[a].desig,30);
cout<<"\n address:"<<sales_emp[a].address.houseno;
cout<<" \n";
cout.write(sales_emp[a].address.area,30);
cout<<" \n";
cout.write(sales_emp[a].address.city,30);
cout<<" \n";
cout.write(sales_emp[a].address.state,30);
cout<<" \n";
cout<<"\n basic pay:"<<sales_emp[a].basic;
cout<<"\n\n";
return;
}

C++ Program

Tuesday, July 31, 2012


Write A C++ Program To Read Values Into A Nested Stucture. 


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct addr
{
int houseno;
char area[30];
char city[30];
char state[30];
};
struct emp
{
int empno;
char name[26];
char desig[26];
addr address;
float basic;
}worker;
int main()
{
clrscr();
cout<<"\n enter employee no.:\n";
cin>>worker.empno;
cout<<"\n name:\n";
gets(worker.name);
cout<<"\n enter designation:\n";
gets(worker.desig);
cout<<"\n enter address:\n";
cout<<"\n house no.:\n";
cin>>worker.address.houseno;
cout<<"\n area:\n";
gets(worker.address.area);
cout<<"\n city:\n";
gets(worker.address.city);
cout<<"\n basic pay:\n";
cin>>worker.basic;


cout<<"\n ***********\n";
cout<<"\n employee no.:\n ";
cout<<worker.empno;
cout<<"\n name:\n ";
puts(worker.name);
cout<<"\n designation:\n ";
puts(worker.desig);
cout<<"\n :address:\n ";
cout<<"\n house no.:\n ";
cout<<worker.address.houseno;
cout<<"\n area:\n ";
puts(worker.address.area);
cout<<"\n city:\n ";
puts(worker.address.city);
cout<<"\n basic pay:\n ";
cout<<worker.basic;
getch();
return 0;
}

COMPUTER SCIENCE: PROGRAMMING IN C++

Tuesday, June 23, 2009

Here are a few C++ practical questions based on stacks, queues and binary files.
1.A queue containing telephone number is to be implemented using a linked list. Write a menu driven program using an object to insert a telephone number in the queue and to delete a telephone number from the queue


2.WAP using binary file create a book file for writing title, author, publisher and year. Display the file contents and perform search operation for a given title


3.A queue containing telephone number is to be implemented using a linked list. Write a menu driven program using an object to insert a telephone number in the queue and to delete a telephone number from the queue.


4.Write a program in C++ to create a binary file “House.dbf” with the following structure : Name, Class, Section and House and to do the following functions :
i) To append a record.
ii) To delete all class 12 records.
iii) To display all the records.


5.Consider a file ITEM.DAT with the following information:INo, IName, Qty, Rate, AmountInclude functions to perform the following:
a).Append records.
b) Modify the record in INo.
c).Display the record.


6.Consider a file EMP.DAT with the following information.Empname, Empno, salary, dept.Include the functions for the following operations
a).Append records.
b).Delete a record on empno.
c). Display all records.


7.A queue containing telephone number is to be implemented using an array. Write a menu driven program to insert a telephone number in the queue and to delete a telephone number from the queue.


{P.S. Pls. request if you need the solution for the above questions and specify the question no. }


8.Write a program in C++ to demonstrate PUSH, POP and display operations on a Array implementation of stack containing Roll no of students.

Blogroll

Bookmark and Share
Powered By Blogger
CBSE 12th Grader.