Nothing Special   »   [go: up one dir, main page]

Studentmark.H #Ifndef #Define Class Private Class Public Int Double Char

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

StudentMark.

#ifndef STUDENTMARK_H
#define STUDENTMARK_H

class StudentMark
{
private:
class Node
{
public:
int StuMatric;
double StuMark;
char StuName[200];
Node*link;
};
Node*pHead;
Node*pCurr;
Node*pPrev;
int numItem;
public:
StudentMark();
~StudentMark();
void AddToFront();
void DeleteFront();
void DeleteMiddle();
bool Traverse(int , int &);
void AddToMiddle();
void printData();
int NumberOfItem();
};
#endif

Main.cpp

#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string>
#include <conio.h>
#include <windows.h>
using namespace std;
#include "StudentMark.h"

int main()
{
cout << "Enter you password: (max 25 characters)" << endl;
// password (char array, doesn't work as string)
char password[25];

int i = 0; // used to index the current character being read


while (true) // infinite loop, broken by pressing return
{
password[i] = _getch(); // get the current character
cout << "*"; // output a star (can be replaced with a different
character)

if (GetAsyncKeyState(VK_RETURN)) // if return has been pressed


break; // break from the loop

i++; // increment our index


}

// now fill the rest of the array with '\0' (NULL) character
for (i; i < strlen(password); i++)
password[i] = '\0';

// output the password (just for testing)


cout << endl << password;

// end of the program


cout << endl << "Press any key to continue . . .";
_getch ();

int choice;
int target;
int location;

StudentMark systems;
cout << " %*%*%*%*%*% Welcome to StudentMark System %*%*%*%*%"
<<endl;
cout << " %& 1- Insert Student Name %&"
<<endl;
cout << " %& 2- Check Inserted Student Name %&"
<<endl;
cout << " %& 3- Find Inserted Student Name %&"
<<endl;
cout << " %& 4- Delete unwanted Student Name %&"
<<endl;
cout << " %*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%"
<<endl<<endl;
cout << "Please Enter Your Choice : " ;
cin>>choice;

do
{
switch(choice)
{
case 1 :
systems("cls");
systems.AddToMiddle();
if (systems.NumberOfItem() == 0)
{
systems.AddToFront();
}
else
{
cout<<"1 student name added!!";
}
getch();
break;
case 2 :
systems("cls");
systems.printData();
getch();
break;
case 3:
system("cls");

cout<<"\nEnter the search student name : ";


cin>>target;
if(systems.Traverse(target,location) == true)
{
cout<<"Student name is found at location :
"<<location<<endl;
}
else
{
cout<<"Student name is not found \n";
}

systems.printData();
getch();
break;
case 4:
systems("cls");

cout<<"\nEnter student name to be deleted : ";


cin>>target;
if(systems.Traverse(target,location) == true)
{
cout<<"Student name is found at location :
"<<location<<endl;
}
else
{
cout<<"Student name is not found \n";
}
if(location == 0)
{
systems.DeleteFront();
}
else
{
systems.DeleteMiddle();
}
getch();
break;

case 5:
return 0;
}
systems("cls");
cout << " %*%*%*%*%*% Welcome to StudentMark System %*%*%*%*%" <<endl;
cout << " %& 1- Insert Student Name %&" <<endl;
cout << " %& 2- Check Inserted Student Name %&" <<endl;
cout << " %& 3- Find Inserted Student Name %&" <<endl;
cout << " %& 4- Delete unwanted Student Name %&" <<endl;
cout << " %& 5- Thanks For Using Our System %&" <<endl;
cout << " %*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%"
<<endl<<endl;
cout << "Please Enter Your Choice : " ;
cin>>choice;
}
while (choice!=5);

return 0;
}

Student.cpp

#include <iostream>
#include<string.h>
using namespace std;
#include "StudentMark.h"

StudentMark::StudentMark()
{
numItem=0;
pHead=0;
}

StudentMark::~StudentMark()
{
}

void StudentMark::AddToMiddle()
{
int StuMatric;
double StuMark;
char Name[200];
Node *pNew=new Node;
cout<<"Please Insert Student Name : ";
cin>>Name;
cout<<"Please Insert Student Mark : ";
cin>>StuMark;
cout<<"Please Insert Student Matric : ";
cin>>StuMatric;
if (numItem==1)
pCurr=pHead;
pNew->StuMatric = StuMatric;
pNew->StuMark = StuMark;
strcpy(pNew->StuName,Name);
pNew->link = pCurr->link;
pCurr->link = pNew;
pCurr = pNew;
numItem++;
}

void StudentMark::AddToFront()
{
int StuMatric;
double StuMark;
char Name[200];
Node *pNew=new Node;
cout<<"The code must between 1-20 and there are no space for
title."<<endl;
cout<<"Please Insert Student Name : ";
cin>>Name;
cout<<"Please Insert Student Mark : ";
cin>>StuMark;
cout<<"Please Insert Student Matric : ";
cin>>StuMatric;
pNew->StuMatric = StuMatric;
pNew->StuMark = StuMark;
strcpy(pNew->StuName,Name);
pNew->link=pHead;
pHead=pNew;
numItem++;

bool StudentMark::Traverse(int target,int &loc)


{
if(numItem == 0)
cout<<" Please Insert The First Name "<<endl;
else
{
pCurr = pHead;
loc = 0;
while(pCurr->StuMatric != target && pCurr->link !=0)
{
pPrev = pCurr;
pCurr = pCurr->link;
loc++;
}
if (pCurr->StuMatric == target)
return true;
else
return false;
}
}

void StudentMark::printData()
{
if (pHead==0)
cout<<"There Are No Any Student Name";
else
{
pCurr=pHead;
while (pCurr != 0)

{
cout<<endl;
cout<<"Student Matric : ";
cout<<pCurr->StuMatric<<" ";
cout<<endl;
cout<<"Student Name : ";
cout<<pCurr->StuName<<" ";
cout<<endl;
cout<<"Student Mark : RM ";
cout<<pCurr->StuMark<<" ";
cout<<endl<<endl;
pCurr=pCurr->link;
}

cout<<"\n";
}
}

void StudentMark::DeleteFront()
{
pHead=pHead->link;
numItem--;
cout<<"Your Request Is Successful."<<endl;
}

void StudentMark::DeleteMiddle()
{
pPrev->link = pCurr->link;
numItem--;
cout<<"Your Request Is Successful."<<endl;
}

int StudentMark::NumberOfItem()
{

return numItem;

You might also like