hi
can someone help me with this:
Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "struct.h"
//#include "database.txt"
/*****function declaration*****/
void getcmd(char*);
void getpass(char*);
void add_std();
void inf_viewer();
void show_list(student*);
/*****main block*****/
int main()
{
/* variables define here */
student std[2];
char lgn, cmd, std_slct, name, tpass[9], spass[9];
int i, j;
/**********************************************/
/* std 1 */
strcpy(std[0].name,"Behzad Shabani");
strcpy(std[0].std_num,"860343061");
std[0].quiz[0] = 18.5;
std[0].quiz[1] = 17;
std[0].quiz[2] = 19;
std[0].exercises[0] = 20;
std[0].exercises[1] = 18;
std[0].exercises[2] = 20;
std[0].project[0] = 20;
/* std 2 */
strcpy(std[1].name,"Sepehr Safi");
strcpy(std[1].std_num,"860343121");
std[1].quiz[0] = 17.5;
std[1].quiz[1] = 15;
std[1].quiz[2] = 13;
std[1].exercises[0] = 20;
std[1].exercises[1] = 19;
std[1].exercises[2] = 17;
std[1].project[0] = 18;
/* std 3 */
strcpy(std[2].name,"Arsalan Barazesh");
strcpy(std[2].std_num,"860343030");
std[2].quiz[0] = 17;
std[2].quiz[1] = 15.5;
std[2].quiz[2] = 14;
std[2].exercises[0] = 20;
std[2].exercises[1] = 19;
std[2].exercises[2] = 18;
std[2].project[0] = 17;
/**********************************************/
/* starting program */
clrscr();
printf("Welcome To The Student Database Manager!");
printf("\nPlease select if you want to login as Student or teacher. (S/T):");
getcmd(&lgn);
/* checking the command */
switch (lgn){
case 'T':
case 't':
/* start of teacher function */
printf("\n\nYou loged in as Teacher.");
/* checking teacher password */
printf("\nPlease enter your password:");
getpass(tpass);
while (strcmp(tpass,"p") != 0){
printf("\n\aWrong password!\nPlease try again:");
getpass(tpass);
}
/* getting a command */
printf("\n\nSelect one of these action:");
printf("\n1. Add a student");
printf("\n2. Delete a student");
printf("\n3. Edit a student");
printf("\nEnter number here:");
getcmd(&cmd);
/* checking the command */
switch (cmd){
case '1':
printf("\n\nadd a student here!");
add_std();
break;
case '2':
printf("\n\ndelete a student!");
show_list(std);
//del_std();
break;
case '3':
printf("\n\nedit a student");
//edt_std();
break;
default:
printf("\n\n\aUnknown command!");
break;
}
//add_inf();
/* end of teacher function */
break;
case 'S':
case 's':
/* start of student function */
clrscr();
printf("You loged in as Student.");
printf("\nfind your name from below and enter its number.\n");
for (i = 0; i<3; i++){
printf("\n%d.", i + 1);
puts(std[i].name);
printf("\n");
}
printf("Now enter the number: ");
scanf("%d", &j);
i = j - 1;
printf("\nWelcome ");
puts(std[i].name);
printf("\nplease enter your password. (default is your student number): ");
getpass(spass);
inf_viewer();
/* end of student function */
break;
default:
printf("\n\aUnknown command!");
break;
}
return 0; // the program succesfully ended
}
/*****function definition*****/
/*****getcmd(): getting commands*****/
// WRITTEN BY: Behzad Shabani
// CALLING FUNCTION: getcmd(&cmd);
void getcmd(char* cmd){
/* function variables */
char ch_ctrl;
int flag = 0;
/* function process*/
while (flag == 0){
*cmd = getche();
if (*cmd == '\b'){
printf("\a ");
continue;
}
else if (*cmd == '\r'){
printf("\a");
continue;
}
while (ch_ctrl != '\r'){
ch_ctrl = getch();
if (ch_ctrl == '\b'){
printf("\b");
break;
}
else if (ch_ctrl != '\r'){
printf("\a");
}
}
if (ch_ctrl == '\b')
continue;
flag = 1;
}
}
/*****getpass(): getting password*****/
// WRITTEN BY: Behzad Shabani
// CALLING FUNCTION: getpass(pass);
void getpass(char* pass){
/* function variables */
char ch;
int flag = 0, i = 0;
/* function process*/
while(flag == 0){
ch = getch();
if (ch == '\r'){
if (i != 0){
pass[i] = NULL;
flag = 1;
continue;
}
printf("\a");
continue;
}
else if (ch == '\b'){
printf("\b");
i--;
continue;
}
printf("*");
pass[i] = ch;
i++;
}
}
/****** add_std() : adding student into the database by teacher ******/
//WRITTEN BY : Sepehr Safi
//CALLING FUNCTION: add_std();
void add_std(){
/* Function Variables */
char* name,*std_num;
float quiz[3],exercises[5],project[2];
int m=0,n=0,b=0,v;
/* Function Process */
printf("\nPlease Enter The Student's Name :");
gets(name);
printf("\nStudent's Name Is :");
puts(name);
printf("\nPlease Enter The Student's Number :");
gets(std_num);
printf("\nStudent's Number Is :");
puts(std_num);
do{
printf("\nEnter The Quiz[%d] point:",m+1);
scanf("%f",&quiz[m]);
printf("\nThe Quiz[%d] point Is :%f",m,quiz[m]);
m++;
}while(m<3);
do{
printf("\nEnter The Exercise Series[%d] point:",n);
scanf("%f",&exercises[n]);
printf("\nThe Exercise Series[%d] point Is :%f",n,exercises[n]);
n++;
}while(n<5);
do{
printf("\nEnter The Project[%d] point:",b);
scanf("%f",&project[b]);
printf("\nThe Project[%d] point Is :%f",b,project[b]);
b++;
}while(b<2);
}
/****** inf_viewer(): showing each student's information ******/
//WRITTEN BY: Sepehr Safi
//CALLING FUNCTION: inf_viewer();
void inf_viewer(){
/* Function Variables */
char* name;
float quiz[3],exercises[5],project[2];
int l=0,k=0,h=0,i;
student* std;
/* Function Process */
printf("\nYou're The Student Number[%d]\n", i+1);
while(l<3){
printf("\nThe Numbers Of Your Quizes Are:");
printf("%f",std[i].quiz[l]);
printf("\n");
l++;
}
while(k<5){
printf("\nThe Numbers Of Your Exercises Are:");
printf("%f",std[i].exercises[k]);
printf("\n");
k++;
}
while(h<2){
printf("\nThe Numbers Of Your Projects Are:");
printf("%f",std[i].project[h]);
printf("\n");
h++;
}
getch();
}
/****** show_list() : show students name 15 by 15 ******/
//WRITTEN BY : Behzad Shabani
//CALLING FUNCTION: show_list();
void show_list(student* std){
/* Function variables */
int i = 0, j = 0, flag = 0;
char cmd;
/* Function process */
do{
while(i < 15 ){
printf("\n%d.", i + j + 1);
puts((*std + i + j)-> name);
i++;
}
printf("\nDo you want to continue the list? (Y/N):");
getcmd(&cmd);
switch (cmd){
case 'y':
case 'Y':
printf("\n\ncontinuing");
continue;
break;
case 'n':
case 'N':
printf("\n\n list ended");
flag = 1;
break;
default:
printf("\n\n\aUnknown command!");
break;
}
j += 15;
i = 0;
}while (flag == 0);
}
and this is the struct.h file:
Code:
/* struct.h
defining new types, students and teacher, made of structure
written by: Behzad Shabani
Improved by: Sepehr Safi
*/
#if !defined(__STRUCT_H)
#define __STRUCT_H
typedef struct student{
char name[45];
char std_num [9];
float quiz[3];
float exercises[5];
float project[2];
};
typedef long int teaherpass[9];
#endif