You are on page 1of 3

Assignment solution of Cs602

Solution :-

 To create a program in Dev-C++ using the graphics.h library that fulfills the given
requirements, follow the steps below. Please note that the graphics.h library is specific to the
Borland compiler and might not work in other environments.

```cpp

#include <iostream>

#include <graphics.h>

#include <conio.h>

using namespace std;

int main() {

int gd = DETECT, gm;

initgraph(&gd, &gm, "");

// Display student ID

outtextxy(10, 10, "Student ID: 123456");

// Input marks for three subjects

int marksA, marksB, marksC;

cout << "Enter marks for Subject A: ";

cin >> marksA;

cout << "Enter marks for Subject B: ";

cin >> marksB;


cout << "Enter marks for Subject C: ";

cin >> marksC;

// Calculate percentage for each subject

int totalMarks = marksA + marksB + marksC;

float percentageA = (float)marksA / totalMarks * 100;

float percentageB = (float)marksB / totalMarks * 100;

float percentageC = (float)marksC / totalMarks * 100;

// Draw the bar chart

int startX = 100, startY = 200;

int barWidth = 50, barGap = 20;

setfillstyle(SOLID_FILL, RED);

bar(startX, startY, startX + barWidth, startY - percentageA * 2);

outtextxy(startX + barWidth / 2 - 10, startY + 10, "A");

setfillstyle(SOLID_FILL, GREEN);

bar(startX + barWidth + barGap, startY, startX + 2 * barWidth + barGap, startY - percentageB * 2);

outtextxy(startX + 3 * barWidth / 2 + barGap - 10, startY + 10, "B");

setfillstyle(SOLID_FILL, BLUE);

bar(startX + 2 * (barWidth + barGap), startY, startX + 3 * (barWidth + barGap), startY - percentageC


* 2);

outtextxy(startX + 5 * barWidth / 2 + 2 * barGap - 10, startY + 10, "C");

getch();
closegraph();

return 0;

```

 "This program creates a bar chart representing the percentage scores for three subjects (A, B,
and C) based on user input. The bars adjust in height according to the marks provided,
maintaining the same colors and layout as in the given output sample. The student ID is
displayed at the specified position in the window."

You might also like