Lab Report
Lab Report
Lab Report
ISLAMABAD
Submitted To:
Sir Adnan Zafar
Submitted By:
M Saad Javed
Registration No:
200401013
Lab Task:
Task No 1: File Search using Applicant Name.
Write a program that lists all applicants with a specific name and display the list on the screen.
The program will take the character array of the specific name from the user and use searching
for substring function i.e., strstr to find the entries with required name and list the entries with
the specific name along with the total number of entries found in the search.
Write a program that lists all applicants with a specific name and display the list on the screen.
The program will take the character array of the specific name from the user and use searching
for substring function i.e., strstr to find the entries with required name and list the entries with
the specific name along with the total number of entries found in the search.
Pseudocode:
Step 1 Use input output stream and file stream header file.
Step 2 Initialize characters which will store the data in information
file.
Step 3 Ask user to input his choice of read, write or find.
Step 4 Use if statement to complete that task.
Step 5 Opening file in which date will be stored using if stream.
Step 6 Using jump statement to get back to the initial position.
Step 7 Initializing character arrays to store information with arrays.
Step 8 Asking user to input his/her data.
Step 9 Using of stream statement for printing the lines that are
stored in department file.
Step 10 Printing option counting using while loop.
Step 11 Asking user to input his choice of department.
Step 12 If option 3 is selected then the function that has been made in
the main will pass and find the entities that’s been stored in the
file.
Step 13 If option 4 is selected then function will tell that this name is
present how many times.
Step 14 Using switch statement there.
Step 15 Storing data in information file.
Step 16 End.
Code:
//M Saad Javed//
//Reg No. 200401013//
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
int main()
{
ofstream fout;
char check;
fout.open("Data.txt", ios::app);//open file to append
if (!fout)
{
cout << "Unable to open file!!\n";//error message if file not open
}
else
{
int s;
cout << "Press 1 for Data Write\n";
cout << "Press 2 for Data read\n";
cout << "Press 3 for Data Search Using name\n";
cout << "Press 4 for Data Search Using Preferences\n";
cin >> s;
if (s == 1)
{
do {
char name[500];
char DOB[500];
char age[3];
int fscmarks;
int matricmarks;
cin.ignore();//clear buffer
//get data from user
cout << "Enter name: ";
cin.getline(name, 500);
cout << "Enter DOB: ";
cin.getline(DOB, 500);
cout << "Enter Age: ";
cin.getline(age, 3);
cout << "FSC Marks: ";
cin >> fscmarks;
cout << "Matric Marks: ";
cin >> matricmarks;
char departments[50][500];//array to store department names
int totaldepartments = 0;//deparments count
ifstream myfile;
myfile.open("departments.txt");//open departments file in read mode
if (!myfile.fail())
{
while (!myfile.eof())//itereate until the end of file is reached
{
myfile.getline(departments[totaldepartments], 500);//read department
in deparments array
totaldepartments++;
}
}
myfile.close();//close file
Output:
Link:
https://replit.com/@SaadJaved/Task-No-1-Lab-6