الاثنين، 9 ديسمبر 2013
8:39 ص

students_marks

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<conio.h>

using namespace std;

class Students_Marks
{
private:
int *Mark;
int length;
int maxsize;
public:
Students_Marks(int maximum){maxsize=maximum; Mark=new int[maxsize]; length=0; cout<<"list is created\n";}
~Students_Marks(){delete[]Mark;}
int Length(){return length;}
bool isEmpty(){return(length==0);}
void insert(int,int);
void Delete();
void display();
};
void Students_Marks :: insert(int k,int m)
{
int i;
if(k<0||k>Length())throw("out of range");
if(Length()==maxsize)throw("list is full");
for(i=Length();i>k;i--)
{
Mark[i]=Mark[i-1];
}
Mark[k]=m;
length++;
}
void Students_Marks :: Delete()
{
int i;
int j;

for(i=0;i<Length();i++)
{
if(Mark[i]<50)
{
for(j=i;j<Length();j++)
Mark[j]=Mark[j+1];
length--;
}
}
}
void Students_Marks :: display()
{
if(Length()==0){cout<<"list is empty";}
cout<<endl;
for(int i=0;i<Length();i++)
cout<<Mark[i]<<"\t";
cout<<endl<<endl;
}

void main()
{
try
{
Students_Marks sm(5);
int m;
int k=1;
int i;
int ch;
 while(k)
 {
 cout<<"Choose what to do:\n1)Insert new mark.\n2)Delete all the marks less than 50.\n3)Display the marks.\n0)Exit.\n==>";
 cin>>ch;
system("cls");
  switch(ch)
  {
  case 0:
  k=0;
  cout<<"Good Bye";
  break;
  case 1:
  cout<<"Enter Student Mark: ";
  cin>>m;
  cout<<"Enter the location: ";
  cin>>i;
  sm.insert(i,m);
 
      break;
  case 2:
  sm.Delete();
      break;
  case 3:
  sm.display();
      break;
  default:cout<<"Error!!!";
  break;
  }
 }
}
catch(char* str)
{
cout<<str;
}
_getch();
}

0 التعليقات:

إرسال تعليق