Lexicographic Increasing Order

Lexicographic increasing order refers to arranging elements or objects in ascending order based on their lexicographic order. In lexicographic order, elements are compared character by character, and the order is determined by the alphabetical or numerical value of each character. For example, consider a list of strings: ["apple", "banana", "cherry", "apricot"]. When arranged in lexicographic increasing order, the list would be ["apricot", "apple", "banana", "cherry"]. The comparison starts with the first character of each string, and if the characters are equal, the comparison moves to the next character. In this case, "apricot" comes before "apple" because 'p' comes before 'p' and 'r' comes before 'p'. Similarly, "apple" comes before "banana" because 'a' comes before 'b'. The concept of lexicographic increasing order

Implement the following class hierarchy: Student: id, name, StudentExam (derived from Student): with n subjects (n can be variable) StudentResult (derived from StudentExam): with percentage, grade. Define a parameterized constructor for each class and appropriate functions to accept and display details. Create n objects of the StudentResult class and display the marklist using suitable manipulators.| CPP programs |

c++ program

 
/*
Cpp Manipulators used are endl and setw().
These manipulators require inclusion of header file <iomanip>

endl : It is used for ending of line in an output.
setw(): This manipulator sets the character spacing in an output i.e
        for e.g. cout<<"Hello"<<setw(3)<<"World";
        here setw(3) will set 3 character spacing between "Hello   World".
*/

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

class student
{
protected:
int rno;
char name[20];
public:
student(int r,char name1[])
{
rno=r;
strcpy(name,name1);
}
void display()
{
cout<<"\n Student rno="<<rno;
cout<<"\n Student name="<<name;
}
};
class student_exam:public student
{
protected:
int *ptr;
int no;
public:
student_exam(int r,char nm[],int n):student(r,nm)
{
no=n;
ptr=new int[no];
}
void accept()
{
for(int i=0;i<no;i++)
{
cout<<"\n Enter Subject mark=";
cin>>ptr[i];
}
}
void display()
{
cout<<"\n==============MARK SHEET============\n";
for(int i=0;i<no;i++)
cout<<"\n Subject"<<i<<":"<<ptr[i]<<"\n";
}
};

class student_result:public student_exam
{
protected:
float per;
char grade;
public:
student_result(int r,char nm[],int no):student_exam(r,nm,no)
{
}
void cal()
{
int t=0;
for(int i=0;i<no;i++)
{
t=t+ptr[i];
}
per=t/no;
if(per>70)
grade='A';
else if(per>=60 && per<70)
grade='B';
else if(per>=50 && per<60)
grade='C';
else if(per>=40 && per<50)
grade='D';
else grade='E';
student::display();
student_exam::display();
cout<<"\n======================================================";
cout<<"\n Percentage="<<per<<"%";
cout<<"\n Grade="<<setw(5)<<grade<<endl;
}
};

main()
{
int no,s;
char name[20];
cout<<"\n Enter roll no=";
cin>>no;
cout<<"\n Enter name=";
cin>>name;
cout<<"\n Enter no of subject=";
cin>>s;
student_result ob(no,name,s);
ob.accept();
cout<<"\n MARKLIST IS \n";
ob.cal();
}
/*
Enter roll no=12

 Enter name=sachin

 Enter no of subject=3

 Enter Subject mark=34

 Enter Subject mark=45

 Enter Subject mark=67

 MARKLIST IS

 Student rno=12
 Student name=sachin
==============MARK SHEET============

 Subject0:34

 Subject1:45

 Subject2:67

======================================================
 Percentage=48%
 Grade=        D
*/
//  CPP programs 

Comments

Popular posts from this blog

Lexicographic Increasing Order

Different Types of Computer Programming Languages