0% found this document useful (0 votes)
22 views5 pages

Cs602 Assignment Solution

The document outlines the assignment for Computer Graphics (CS602) due on May 9, 2025, focusing on creating a line chart to visualize cricket scores using Dev-C++. It specifies submission rules, programming requirements, and provides a sample C++ program using the graphics.h library. Students must ensure their assignment is submitted in .cpp format and adhere to the guidelines to avoid penalties.

Uploaded by

good bad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

Cs602 Assignment Solution

The document outlines the assignment for Computer Graphics (CS602) due on May 9, 2025, focusing on creating a line chart to visualize cricket scores using Dev-C++. It specifies submission rules, programming requirements, and provides a sample C++ program using the graphics.h library. Students must ensure their assignment is submitted in .cpp format and adhere to the guidelines to avoid penalties.

Uploaded by

good bad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Computer Graphics (CS602) Total marks = 20

Assignment # 01 Deadline = Friday


May-9-2025
Spring 2025

Please carefully read the following instructions before attempting the assignment.

RULES FOR MARKING


It should be clear that your assignment would not get any credit if:
 The assignment is submitted after the due date.
 The submitted assignment does not open, or the file is corrupted.
 Strict action will be taken if the submitted solution is copied from any other student or the
internet.

You should consult the recommended books to clarify your concepts, as handouts are insufficient.
You are supposed to submit your assignment in .cpp format only.
Any other formats like scanned images, doc, docx, PDF, ZIP, RAR, PPT, BMP, etc. will not be accepted.

Objective
The objective of this assignment is to;
 Learn and practice basic computer graphics concepts like lines, circles, rectangles, and texts
using Dev-C++. (You can download the Dev-C++ setup from LMS)
 Learn to draw shapes and patterns by using graphics library functions.
Instructions
You have to do the following steps first to perform the task.
1. Install Dev-C++ from your LMS.
2. Read the file "Add graphics in Dev cpp" thoroughly and follow the instructions in the file
adequately provided to you on your LMS.

Submission
You are supposed to submit your assignment in .cpp format only.

Topic Covered
Lecture 01 to Lecture 11

NOTE

No assignment will be accepted via email after the due date (whether due to load shedding, internet
malfunctioning, etc.). Hence, refrain from uploading assignments within the last hour of the deadline. It is
recommended that the solution be uploaded at least two days before its closing date.

If you find any mistakes or confusion in the assignment (Question statement), please consult your instructor
before the deadline. After the deadline, no queries will be entertained in this regard.

For any query, feel free to email me at:


[email protected]
Question No 01 Marks (20)
Creating a Line Chart to Show Cricket Scores Over 10 Overs
Scenario:
You are developing a score visualization tool for a sports analytics company. Your task is to build a program
that plots a line chart to compare the runs scored by two cricket teams over 10 overs. This chart will help
users quickly analyze the scoring trends and performance comparison between both teams. The program
should be implemented in Dev-C++ using the graphics.h library.

Requirements:
1. Student ID must be displayed in the top-right corner of the window.
2. Create two arrays or variables:
o teamA[10] and teamB[10] to store runs scored in each over by both teams.
o Example values:
 Team A: {6, 8, 12, 10, 9, 5, 7, 11, 13, 8}
 Team B: {5, 7, 10, 9, 11, 6, 8, 12, 14, 9}
3. Plot both teams’ scores on the same chart using two different colored lines (e.g., blue for Team A,
red for Team B).
4. Label the X-axis as "Overs (1 to 10)" and the Y-axis as "Runs Scored".
5. Mark and connect the data points with lines for both teams.
6. Clearly show:
o Data points with small circles or markers.
o Legends to differentiate Team A and Team B.
7. Display:
o Total runs scored by each team.
o A message at the bottom indicating which team won based on total runs.
8. Ensure:
o The chart is clear and visually accurate.
o Any change in score arrays reflects dynamically on the graph.

Output Sample:

Assignment Solution:
Here’s a Dev-C++ program using graphics.h that fulfills all your specified requirements, including plotting a
line chart comparing cricket scores for two teams over 10 overs:

C++ Program (Using graphics.h in Dev-C++)

#include <graphics.h>
#include <conio.h>
#include <iostream>
#include <string.h>
Using namespace std;

Int main() {
// Initialize graphics
Int gd = DETECT, gm;
Initgraph(&gd, &gm, “”);

// Example runs for 10 overs


Int teamA[10] = {6, 8, 12, 10, 9, 5, 7, 11, 13, 8};
Int teamB[10] = {5, 7, 10, 9, 11, 6, 8, 12, 14, 9};

// Calculate totals
Int totalA = 0, totalB = 0;
For (int I = 0; I < 10; i++) {
totalA += teamA[i];
totalB += teamB[i];
}

// Draw axes
Line(50, 400, 600, 400); // X-axis
Line(50, 100, 50, 400); // Y-axis

// Labels
Outtextxy(10, 70, “Runs Scored”);
Outtextxy(280, 420, “Overs (1 to 10)”);

// Draw X-axis ticks and labels


For (int I = 0; I < 10; i++) {
Int x = 80 + I * 50;
Line(x, 395, x, 405);
Char overLabel[3];
Sprintf(overLabel, “%d”, I + 1);
Outtextxy(x – 5, 410, overLabel);
}

// Draw Y-axis ticks and labels


For (int I = 0; I <= 14; I += 2) {
Int y = 400 – I * 20;
Line(45, y, 55, y);
Char runLabel[3];
Sprintf(runLabel, “%d”, i);
Outtextxy(20, y – 5, runLabel);
}

// Plot Team A in Blue


Setcolor(BLUE);
For (int I = 0; I < 9; i++) {
Int x1 = 80 + I * 50;
Int y1 = 400 – teamA[i] * 20;
Int x2 = 80 + (I + 1) * 50;
Int y2 = 400 – teamA[I + 1] * 20;
Line(x1, y1, x2, y2);
Fillellipse(x1, y1, 4, 4);
}
// Last point
Fillellipse(80 + 9 * 50, 400 – teamA[9] * 20, 4, 4);

// Plot Team B in Red


Setcolor(RED);
For (int I = 0; I < 9; i++) {
Int x1 = 80 + I * 50;
Int y1 = 400 – teamB[i] * 20;
Int x2 = 80 + (I + 1) * 50;
Int y2 = 400 – teamB[I + 1] * 20;
Line(x1, y1, x2, y2);
Fillellipse(x1, y1, 4, 4);
}
// Last point
Fillellipse(80 + 9 * 50, 400 – teamB[9] * 20, 4, 4);

// Legend
Setcolor(BLUE);
Outtextxy(500, 120, “Team A”);
Rectangle(470, 120, 490, 130);
Floodfill(471, 121, BLUE);

Setcolor(RED);
Outtextxy(500, 150, “Team B”);
Rectangle(470, 150, 490, 160);
Floodfill(471, 151, RED);

// Display totals
Setcolor(WHITE);
Char result[100];
Sprintf(result, “Team A Total: %d Team B Total: %d”, totalA, totalB);
Outtextxy(180, 20, result);

// Display winner
If (totalA > totalB)
Outtextxy(180, 440, “Team A Wins!”);
Else if (totalB > totalA)
Outtextxy(180, 440, “Team B Wins!”);
Else
Outtextxy(180, 440, “Match is Drawn!”);

// Display Student ID
Outtextxy(500, 20, “Student ID: 12345678”); // Replace with your actual ID

Getch();
Closegraph();
Return 0;
}

Instructions to Compile and Run in Dev-C++:

1. Install Dev-C++ and ensure graphics.h and winbgim are configured properly.

2. Create a new project or source file, paste the code, and replace “12345678” with your real Student
ID.

3. Compile and Run.

You might also like