-
student database program [was: can u solve this program :P]
Write a menu driven program that performs the following tasks where each task gets
performed by a separate function:
a) Reads the information of up to 30 students and stores them in parallel arrays. The information for each student consists of three things:
• Student Name
• Student Number
• Course Letter Grade
Function prototype:
void readInfo(string names[], int numbers[], char grades[], int& count);
b) Display the information of all students. If no information available, an appropriate message is printed. Function prototype:
void printInfo(string names[], int numbers[], char grades[], int count);
c) Sort the names of the students in alphabetical order. Function prototype:
void sortInfo(string names[], int numbers[], char grades[], int count);
d) Search students information using a student number. If found, the index of the student in the array is returned to the main function. The main function then displays the information of the matched student otherwise an appropriate message is printed. The number inputted by the user in the main function is passed to the searchInfo function as a parameter. Function prototype:
int searchInfo(int num, int numbers[], int count);
e) Given a letter grade, display the names of all students with this letter grade. If no match is found an appropriate message is printed. The letter grade to be matched is inputted by the user in the main function then passed to gradesInfo as a parameter. Function prototype:
void gradesInfo(char grade, string names[], char grades[], int count);
-
I suggest that you read the forum's eqtiquette first, focussing on the "homework assignments" section.
Danny Kalev
-
Yup, sure can write that program. Can you?
-
no i can`t so that i asked u :P
-
How far have you gotten in trying to write it? Are you stuck somewhere?
-
I solve this and i stuck here..!!!
#include <iostream>
#include <string>
using namespace std;
//*********************************************************************
void readinfo(string name[] ,int id[],char grade[],int &count )
{
int i;
for(i=0;i<2;i++)
{
cout<<"enter student name :";
cout<<endl;
cin>>name[i];
cout<<"enter student id:";
cout<<endl;
cin>>id[i];
cout<<"enter the gradr:";
cout<<endl;
cin>>grade[i];
count++;
}
}
//***********************************************************#include <iostream>
#include <string>
using namespace std;
//*********************************************************************
void readinfo(string name[] ,int id[],char grade[],int &count )
{
int i;
for(i=0;i<2;i++)
{
cout<<"enter student name :";
cout<<endl;
cin>>name[i];
cout<<"enter student id:";
cout<<endl;
cin>>id[i];
cout<<"enter the gradr:";
cout<<endl;
cin>>grade[i];
count++;
}
}
rt (string name[],int id[],char grade[],int count)
{
int i,j,s;
string small;
for(i=0;i<2;i++)
{
small=name[i];
for(j=i+1;j<2;j++)
{
if(name[i]<small)
{
small=name[i];
s=j;
}
name[s]=name[i];
name[i]=small;
}
}
}*/
//****************************************************************************
void sort(string stud[],int count)
{
int i,j,min;
student hold;
for(i=0; i <=count; i++)
{
min = i;
for(j=i+1; j < count; j++)
if(strcmp(stud[j].fname,stud[min].fname)<0)
min = j;
printf("%d\n",min);
printf("%s\n",stud[min].fname);
if(i != min)
{
hold =stud[i];
stud[i]= stud[j];
stud[j]= hold;
strcpy(hold.fname,stud[i].fname);
strcpy(stud[i].fname,stud[min].fname);
strcpy(stud[min].fname,hold.fname);
strcpy(hold.lname,stud[i].lname);
strcpy(stud[i].lname,stud[min].lname);
strcpy(stud[min].lname,hold.lname);
}
}
for(i=0; i <count; i++)
{
printf("\n id =%d first =%s last = %s midterm = %0.2f final = %0.2f
",stud[i].id,
stud[i].fname,stud[i].lname,stud[i].midterm,stud[i].final);
}
return;
}
//****************************************************************************
int main ()
{
string name [2];
int id[2];
int i=0,count=0;
char grade[2],ch;
cout<<"Enter your chose:";
cin>>ch;
while (ch!='q')
{
switch (ch)
{
case 'a':readinfo(name,id,grade,count);break;
case 'b':printinfo(name,id,grade,count);break;
case 'c':sort(name,id,grade,count);break;
}
cout<<"Enter your chose:";
cin>>ch;
}
return 0;
}
can u correct it and complete it PLZ :)
-
Looks like you've been picking up code snippets in various places. your whole "sort" method looks like it is dealing with an array of student objects with, among other things, fname and lname data members.
Put some work into cleaning up this conglomeration, putting some design sense into it. What happens when you try to compile it?
-
I cant complete it i dont know why..!!
can u help :)
-
Hi bawen,
I had a look at your code and there are quite a few syntax and other errors.
first of all you use a class "student" which is defined nowhere. Including the header file in your code might get rid of some of the errors.
Your function readinfo() is defined twice, there is an unmatched closing comment (*/) that creates a syntax error. One of the parameters of your sort algorithm is an array of strings. string doesn't have a member fname. Are you sure you are using the right parameter-type? Probably you want to use your sudent class instead?.
Sort out these major mistakes and see how far you get.
Cheers,
D
DKyb-------------------------------
Life is a short warm moment -
Death is the long cold rest.
Pink Floyd
-------------------------------
Similar Threads
-
By hafizfarooq in forum VB Classic
Replies: 2
Last Post: 10-28-2005, 11:32 PM
-
By ram_son in forum VB Classic
Replies: 0
Last Post: 04-24-2005, 12:13 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks