Write a program, which reads a list of student records from a file in batch mode. Each student record comprises a roll number and student name, and the student records are separated by commas. An example data in the file is given below.
· SP18-BCS-050 (Ali Hussan Butt), SP19-BCS-154 (Huma Khalid), FA19-BSE-111 (Muhammad Asim Ali), SP20-BSE-090 (Muhammad Wajid), SP17-BCS-014 (Adil Jameel)
The program should store students roll numbers and names separately in 2 parallel arrays named names and rolls, i.e. in the above case, 1st element of names contains “Ali Hussan Butt” and 1st element of rolls contain “SP18-BCS-321”; similarly, 2nd element of names contains “Huma Khalid” and 2nd element of rolls contain “SP19-BCS-154” and so on. Hint: You may use delimiters string “() ,”. Ignore empty strings returned as tokens (i.e. strings with length 0), if any.
In the end, first, display roll numbers and names for only the following students:
· Who are enrolled in BCS program.
· Whose roll number is between 100 and 200. (Hint: you can extract last 3 characters of roll number, convert it into integer and then check range 100-200)
For example, in the above case, only following students should be displayed.
1. SP19-BCS-154 (Huma Khalid)
NOTE: 10
1)USE C LAUNGAGE ONLY AND NO FILE HANDLING ALLOWED
2)You can use string tokenization for seprating delimeters then save roll and names in two different arrays named as student_name and student_rollno i.e Parallel arrays and then display both the arrays.
3)Again use the string tokenization to separate Programs in student_rollno(using your roll no array) with the help of strcmp() function to separate BCS students from BSE in loop and in the same loop make sure that only BCS students of roll no between 100-200 are chosen and make those roll no and student names printed.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* cpy_str(char *source)
{
char *target=(char*)malloc(sizeof(source));
int i=0;
while(source[i]!='\0')
{
target[i]=source[i];
i++;
}
target[i]='\0';
return target;
}
int main()
{
char str[]="SP18-BCS-050(Ali Hussan Butt),SP19-BCS-154(Huma
Khalid),FA19-BSE-111(Muhammad Asim Ali),SP20-BSE-090(Muhammad
Wajid),SP17-BCS-014(Adil Jameel)";;
char *roll_no[100];
char *names[100];
int count=0;
char* token;
char *str_ptr=str;
char* name_ptr;
char* rno_ptr;
while ((token = strtok_r(str_ptr,",",&str_ptr)))
{
rno_ptr= strtok_r(token,"(",&token);
roll_no[count]=rno_ptr;
name_ptr= strtok_r(token,")",&token);
names[count]=name_ptr;
count=count+1;
}
printf("List:\n");
for(int i=0;i<count;i++)
{
printf("%s(%s)\n", roll_no[i],names[i]);
}
printf("BCS students of roll no between 100-200\n");
for(int i=0;i<count;i++)
{
char* token1="",*token2="",*token3="";
rno_ptr=cpy_str(roll_no[i]);
//printf("%s\n", rno_ptr);
token1=strtok(rno_ptr,"-");
token2=strtok(NULL,"-");
token3=strtok(NULL,"\0");
//printf("%s\n", roll_no[i]);
//printf("%s\n", token1);
//printf("%s\n", token2);
//printf("%s\n", token3);
if((strcmp(token2,"BCS"))==0)
{
int temp=atoi(token3);
if((temp>=100)&&(temp<=200))
{
printf("%s(%s)\n", roll_no[i],names[i]);
}
}
}
return 0;
}
OUTPUT:
List:
SP18-BCS-050(Ali Hussan Butt)
SP19-BCS-154(Huma Khalid)
FA19-BSE-111(Muhammad Asim Ali)
SP20-BSE-090(Muhammad Wajid)
SP17-BCS-014(Adil Jameel)
BCS students of roll no between 100-200
SP19-BCS-154(Huma Khalid)
Program with no
strtok_r and without malloc function
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char str[]="SP18-BCS-050(Ali Hussan Butt),SP19-BCS-154(Huma
Khalid),FA19-BSE-111(Muhammad Asim Ali),SP20-BSE-090(Muhammad
Wajid),SP17-BCS-014(Adil Jameel)";;
char *list[100];
char *roll_no[100];
char *names[100];
int count=0;
char* list_ptr;
char *str_ptr=str;
char *tk = strtok(str_ptr,",");
while (tk!=NULL)
{
list[count]=tk;
//printf("%s\n",list[count]);
tk= strtok(NULL,",");
count=count+1;
}
for(int i=0;i<count;i++)
{
tk = strtok(list[i],"(");
if(tk!=NULL)
{
roll_no[i]=tk;
}
tk= strtok(NULL,")");
if(tk!=NULL)
{
names[i]=tk;
}
}
printf("List:\n");
for(int i=0;i<count;i++)
{
//printf("%s\n",list[i]);
printf("%s(%s)\n", roll_no[i],names[i]);
}
printf("BCS students of roll no between 100-200\n");
for(int i=0;i<count;i++)
{
char* token1="",*token2="",*token3="";
char rno_ptr[100];
for(int j=0;roll_no[i][j]!='\0';j++)
{
rno_ptr[j]=roll_no[i][j];
}
token1=strtok(rno_ptr,"-");
token2=strtok(NULL,"-");
token3=strtok(NULL,"\0");
if((strcmp(token2,"BCS"))==0)
{
int temp=atoi(token3);
if((temp>=100)&&(temp<=200))
{
printf("%s(%s)\n", roll_no[i],names[i]);
}
}
}
return 0;
}
OUTPUT:
List:
SP18-BCS-050(Ali Hussan Butt)
SP19-BCS-154(Huma Khalid)
FA19-BSE-111(Muhammad Asim Ali)
SP20-BSE-090(Muhammad Wajid)
SP17-BCS-014(Adil Jameel)
BCS students of roll no between 100-200
SP19-BCS-154(Huma Khalid)
Write a program, which reads a list of student records from a file in batch mode....
Write a C++ Program that reads in a file containing the names of the students in the class into an array of string elements. The program should use the random number generator to shuffle the order of the student names in the array and create pairs of students as final project team assignments. If the number of students is an odd number, then one of the groups should have a third team member.
Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...
Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...
Write the code to maintain a list of student records. The main flow of your program should be to read all information from file(s) and place it in arrays, loop and do stuff with the records (e.g., add, update, look up, etc.), before exiting optionally write the new information back to the file(s) before exiting. Please note the files are only accessed at the beginning and the end, do not change the files during the "do stuff loop" (unless you...
Write a program that processes a data file of names in which each name is on a separate line of at most 80 characters. Here are two sample names: Hartman-Montgomery, Jane R. Doe, J. D. Strings On each line the surname is followed by a comma and a space. Next comes the first name or initial, then a space and the middle initial. Your program should scan the names into three arrays— surname , first , and middle_init . If...
C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...
Help in JAVA please Write a program that reads a list of students (first names only) from a file. It is possible for the names to be in unsorted order in the file but they have to be placed in sorted order within the linked list. The program should use a doubly linked list. Each node in the doubly linked list should have the student’s name, a pointer to the next student, and a pointer to the previous student. Here...
Using c++ Write a program that reads in a list of up to 25 first names from an input file nameData.txt and allows the user to display the name data, sort it in ascending or descending order, count the number of occurrences of a given name, or exit the program. The input file consists of a single names per line with each line terminated with an end of line (i.e. using Enter key to end the line). Your program should...
In C++, write a complete program that receives a series of student records from the keyboard and stores them in three parallel arrays named studentID and courseNumber and grade. All arrays are to be 100 elements. The studentID array is to be of type int and the courseNumber and grade arrays are to be of type string. The program should prompt for the number of records to be entered and then receive user input on how many records are to...
Your assignment is to write a grade book for a teacher. The
teacher has a text file, which includes student's names, and
students test grades. There are four test scores for each student.
Here is an example of such a file:
Count: 5
Sally 78.0 84.0 79.0 86.0
Rachel 68.0 76.0 87.0 76.0
Melba 87.0 78.0 98.0 88.0
Grace 76.0 67.0 89.0 0.0
Lisa 68.0 76.0 65.0 87.0
The first line of the file will indicate the number of students...