u

VB Projects

Get all Visual Basic Projects here..

ASP Dot Net Projects

Get all Asp Dot Net Projects.

C++ Projects and Programs

Get all C++ Projects and Programs here...

PHP Projects

Get all PHP Projets here..

JAVA Projects

Get All JAVA Projects here...

Friday 14 September 2012

C++ Program to define a function and incorporate the array of structures to input and store any 30 records

C++ Program to define a function and incorporate the array of structures to input and store any 30 records

Display the following using functions incorporated through structure definition viz. display of all entered records,sort the records according to the marks in descending order and display of sorted records.



#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<stdio.h>

struct ward

{

char name[20];

float marks;

} stud[5];

void display();

void sort();

void dispsort();

main()

{

clrscr();

// Data entry

clrscr();

cout<<"D A T A : ENTRY PROCESS: Enter 5 Records Initially"<<endl;

for(int i=0;i<5;i++)

{

cout<<"\nEnter name";

cin>>stud[i].name;

cout<<"\nEnter marks";

cin>>stud[i].marks;

}

       clrscr();

       display(); // Call of Function

       // to display data entered.

       cout<<"Press any key to continue";

       getch();

       clrscr();

       sort(); // Call of Function

// to sort data

       clrscr();

       cout<<"Press any key to display ";

       cout<<"the sorted data";

       getch();

       dispsort(); // Call of Function

// to display the sorted data.

       cout<<endl;

       cout<<"Press any key to continue";

       getch();

       return 0;

}

void display() // Definition of the function

// to display the data values.

{

clrscr();

cout<<"DATA LIST AS ENTERED";

cout<<endl;

for(int k=0;k<5;k++)

{

cout<<"NAME OF THE STUDENT IS ";

cout<<stud[k].name;

cout<<endl;

cout<<"HIS MARKS IS ";

cout<<stud[k].marks;

cout<<endl;

cout<<"***************************************";

cout<<endl;

cout<<"***************************************";

cout<<endl;

}

}

void sort() // Definition of the sort function.

{

// sorting done according to marks.

char nam[20];

int mark=0;

for(int r=0;r<4;r++)

{

for(int s=r+1;s<5;s++)

{

if (stud[r].marks < stud[s].marks)

{

strcpy(nam,stud[r].name);

strcpy(stud[r].name,stud[s].name);

strcpy(stud[s].name,nam);

mark=stud[r].marks;

stud[r].marks=stud[s].marks;

stud[s].marks=mark;

}

}

}

}

void dispsort() // Definition of the function

// to print the sorted data.

{

clrscr();

cout<<"Display of sorted data according to marks";

cout<<endl;

display();

cout<<endl;

cout<<"End of data encountered";

cout<<endl;

cout<<"Press any key to continue";

getch();

}

C++ Program to sort the given strings in Ascending order

C++ Program to sort the given strings in Ascending order

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
clrscr();
char name[10][20],temp[10][20];
int i,j,n;
printf ("\nENTER THE NUMBER OF NAMES TO BE ASCENDED : ");
scanf ("%d",&n);
for (i=0;i<n;i++)
{
printf ("ENTER THE %d NAME : ",i+1);
scanf ("%s",name[i]);
}
printf ("\n The ascending order of the names is : \n ");
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (strcmp(name[i],name[j])>0)
{
strcpy (temp[i],name[i]);
strcpy (name[i],name[j]);
strcpy (name[j],temp[i]);
}
}
printf ("\n%s",name[i]);
}
getch();
}

C++ Program to input a string and a character. Print the frequency of the character within the string

C++ Program to input a string and a character. Print the frequency of the character within the string

 #include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
main()
{
clrscr();
char name[40],input;
int l=0,count=0;
cout<<"Enter any word "<<endl;
gets(name);
cout<<endl<<"Enter the character to print the frequency";
cin>>input;
l = strlen(name);
cout<<endl;
for (int a=0;a<l;a++)
{
if (name[a]==input) count = count + 1;

}
cout<<endl<<"The frequency of "<<input<<" is "<<count<<endl;
getch();
return 0;
}

C++ Program to input any string and print the number of 'the'

C++ Program to input any string and print the number of 'the'

 #include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
main()
{
clrscr();
char name[50];
int l=0,c=0;
cout<<"Enter any string "<<endl;
gets(name);
l = strlen(name);
cout<<endl;
for(int i=0;i<=l;i++)
{
if ((name[i]=='t') && (name[i+1]=='h') && ((name[i+2])=='e'))
c=c+1;}
cout<<endl;
cout<<"total the is "<<c;
getch();
return 0;

}

C++ Program to input any ten numbers and print them in ascending order

C++ Program to input any ten numbers and print them in ascending order

 #include<iostream.h>
#include<conio.h>
main()
{
int number[10],a,b,c,d;
clrscr(); // clear the screen
cout<<"Enter the elements of the array"<<endl;
for(int i=0;i<10;i++)
{
cout<<"Enter number for cell "<<i<<endl;
cin>>number[i];
}
cout<<endl<<"Thank You ! The data entry is over"<<endl;
cout<<"Press any key to continue";
getch();
clrscr();
// sorting of data
for(int j=0;j<9;j++)
{
for(int k=j+1;k<10;k++)
{
if (number[j]>number[k])
{
a=number[j];
number[j]=number[k];
number[k]=a;
}
}
}
cout<<"The list in ascending order is ";
cout<<endl;
for(i=0;i<10;i++)
cout<<number[i]<<"\t";
cout<<endl<<"Press any key to return to the editor";
getch();
return 0;
}

C++ Program using function allows the user to enter a number and than rounds it off,correct to the nearest integer

C++ Program using function allows the user to enter a number and than rounds it off,correct to the nearest integer


#include <iostream.h>
#include <conio.h>             //HEADER FILES


void main()                  // MAIN FUNCTION

    {
     clrscr();                // CLEAR THE SCREEN

     float input=0,remainder=0;    // INITIALIZATION AND DECLARATION OF
     int whole=0,answer=0;        // VARIABLES

     gotoxy (15,15);                        // GO TO A PARTICULAR POSITION

     cout << "ENTER A FLOAT NUMBER : ";     // MESSAGE

     cin >> input;            // STORE THE INPUT INTO THE VARIABLE

     whole = input;        // THIS LINE STORES THE INTEGER PART OF THE VALUE
               // INTO A SEPERATE VARIABLE

     remainder = input - whole;   // REMAINDER IS THE VALUE AFTER THE DECIMAL
                 // POINT

     if (remainder >= 0.5)       // IF REMAINDER IS GREATER THAN 0.5

    answer = whole + 1;     // ADD 1 TO THE VALUE

     else                      // OTHERWISE

    answer = whole;      // KEEP THE INTEGER PART AS IT IS

     gotoxy (15,16);
     cout << "Rounded Off Number Is : " << answer;  // DISPLAY THE ANSWER

     getch();               // WAIT FOR AN INPUT FROM THE USER.

    }      // END OF FUNCTION

C++ Program to Rotates a word

C++ Program to Rotates a word
This program prints all the rotation of a word.
Say if the input word is "space", then it prints
>>space
>>paces
>>acesp
>>cespa

>>espac

 #include <stdio.h>
#include <string.h>
#include <conio.h>
void main()
{
char w[50],buf[50],temp[50],buf2[10];
clrscr();
printf("Enter a word to see it's rotation :");
fflush(stdin);
gets(w);
strcpy(temp,w);
printf("All the rotation of the word \"%s\" are :",w);
for(int i=0;i<strlen(w);i++)
{
strcpy(buf,strnset(w,' ',i));
for(int j=0;j<i;j++)
buf2[j]=temp[j];
buf2[j]='\0';
strcat(buf,buf2);
//To straighten the output
gotoxy(strlen(w)-i,4+i);
puts(buf);
}
getch();
}

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More