Cs602 Assignment Solution
Cs602 Assignment Solution
Please carefully read the following instructions before attempting the assignment.
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.
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:
#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, “”);
// 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)”);
// 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;
}
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.