Program 3 Write a C program using arrays that will 1Read in

Program 3

Write a C++ program using arrays that will;

1.Read in data from a data file of ten(10) records,

2.Print the original data,

3.Using the Bubble Sort algorithm, sort the data by year,

4.Print the sorted data,

5.Then, prompt the user to enter a year,

6. Use the Linear Search algorithm to find the record with that year

7. Then, display the found record, if record not found, print “Not Found”.

NOTE: Use functions for your output, sort and search routines.

Name Year Tuition

Jason 2012 1222.33

Jackson 1992 900.23

Raymond 1993 2023.22

Korrey 1999 19920.22

Ellis 2000 700.23

Larry 2013 39.22

Micheal 2014 100.23

Isiah 2011 102.44

Solution

# include <stdio.h>
# include <conio.h>
# include <string.h>

struct file1{
double tuition ;
char name[20];
double year;
};

main()
{
struct file1 t;
FILE *fp;
long tuition;
char sname[20],c;
int ch;
while(1)
{
clrscr();
printf(\"\\t\\t MENU\ \");
printf(\"1. TO ADD THE RECORD IN THE FILE.\ \");
printf(\"2. TO SEARCH THE RECORD BY NAME.\ \");
printf(\"3. TO SORT THE RECORD .\ \");
printf(\"4. TO SEE ALL THE RECORD.\");
printf(\"5. TO EXIT.\ \");
printf(\"ENTER YOUR CHOICE:->\");
scanf(\"%d\",&ch);
switch(ch)
{
case 1:
fp=fopen(\"file1.txt\",\"ab\");
while (1)
{
clrscr();
printf(\"\ ENTER THE NAME \");
scanf(\"%s\",t.name);
fflush(stdin);
printf(\"\ ENTER THE YEAR\");   
scanf(\"%s\",t.year);
fwrite(&t,sizeof(t),1,fp);
fflush(stdin);
printf(\"\ \ WISH TO CONTINUE?(Y/N)\");
scanf(\"%c\",&c);
if(c==\'n\' || c==\'N\')
break;
}
fclose(fp);
break;
case 2:
fp=fopen(\"file1.txt\",\"rb\");
clrscr();
printf(\"ENTER THE NAME :->\");
scanf(\"%s\",sname);
while(fread(&t,sizeof(t),1,fp))
{
if(strcmp(sname,t.name)==0)
{
printf(\"\ \\t%ld\\t %s\\t %s\",t.year,t.name,t.tuition);
getch();
break;
}
}
fclose(fp);
getch();
break;
           case 3:ifstream myfile (\"bubblesort.txt\");

if (myfile.is_open())

{

while ( myfile.good() )

{

getline (myfile,line);

cout << line << endl;

}

myfile.close();

}

else cout << \"Unable to open file\";

                  
case 4:
exit(1);
}
}
getch();

}
  

Program 3 Write a C++ program using arrays that will; 1.Read in data from a data file of ten(10) records, 2.Print the original data, 3.Using the Bubble Sort alg
Program 3 Write a C++ program using arrays that will; 1.Read in data from a data file of ten(10) records, 2.Print the original data, 3.Using the Bubble Sort alg
Program 3 Write a C++ program using arrays that will; 1.Read in data from a data file of ten(10) records, 2.Print the original data, 3.Using the Bubble Sort alg

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site