0% found this document useful (0 votes)
229 views2 pages

C++ Program for ASCII Art Display

The document contains C++ code that reads in data from text files containing character drawings and stores the data in 2D arrays, then loops through the arrays to output the drawings. It prompts the user to input a filename, opens and reads in the file, storing the character at each x,y coordinate into a 2D array based on the rows and columns specified in the file. It then loops through the array to output the drawing represented by the characters at each position.

Uploaded by

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

C++ Program for ASCII Art Display

The document contains C++ code that reads in data from text files containing character drawings and stores the data in 2D arrays, then loops through the arrays to output the drawings. It prompts the user to input a filename, opens and reads in the file, storing the character at each x,y coordinate into a 2D array based on the rows and columns specified in the file. It then loops through the array to output the drawing represented by the characters at each position.

Uploaded by

saadyassine21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1: // Saad Yassine and Alistair MacIver

2: #include <iostream>
3: #include <cmath>
4: #include <cstdlib>
5: #include <fstream>
6: #include <iomanip>
7:
8: using namespace std;
9:
10: int main()
11: {
12: string filename;
13: cout << "Enter filename: ";
14: cin >> filename;
15: ifstream fin(filename.c_str());
16:
17: if (!fin)
18: {
19: cout << "File not found" << endl;
20: system ("PAUSE");
21: return EXIT_FAILURE;
22: }
23:
24: const int ROW_SIZE = 200, COL_SIZE = 79;
25:
26: char drawing[ROW_SIZE][COL_SIZE];
27:
28: int NumberOfRows = 0;
29: fin >> NumberOfRows;
30:
31: int row = 0, coloumn = 0;
32:
33: char symbol = ' ';
34:
35: for(int rowSetup = 0; rowSetup < ROW_SIZE; rowSetup++)
36: {
37: for(int coloumnSetup = 0; coloumnSetup < COL_SIZE; coloumnSetup++)
38: drawing[rowSetup][coloumnSetup] = ' ';
39: }
40:
41: while(fin >> row >> coloumn >> symbol)
42: {
43: drawing[row][coloumn] = symbol;
44: }
45:
46: for(int rowLoc = 0; rowLoc < NumberOfRows-1; rowLoc++)
47: {
48: for(int coloumnLoc = 0; coloumnLoc < COL_SIZE; coloumnLoc++)
49: cout << drawing[rowLoc][coloumnLoc];
50: cout << endl;
51: }
52:
53: [Link]();
54: return EXIT_SUCCESS;
55: }
56: /*
57: Enter filename: homer_mapped.txt
58: __
59: _ ,___,-'",-=-.
60: __,-- _ _,-'_)_ (""`'-._\ `.
61: _,' __ |,' ,-' __) ,- /. |
62: ,'_,--' | -' _)/ `\
63: ,',' ,' ,-'_,` :
64: ,' ,-' ,(,-( :
65: ,' ,-' , _ ;
66: / ,-._/`---' /
67: / (____)(----. ) ,'
68: / ( `.__, /\ /,
69: : ;-.___ /__\/|
70: | ,' `--. -,\ |
71: : / \ .__/
72: \ (__ \ |_
73: \ ,`-, * / _|,\
74: \ ,' `-. ,'_,-' \
75: (_\,-' ,'\")--,'-' __\
76: \ / // ,'| ,--' `-.
77: `-. `-/ \' | _,' `.
78: `-._ / `--'/ \
79: -hrr- ,' | \
80: / | \
81: ,-' | /
82: / | -'
83:
84: Enter filename: mickey_mapped.txt
85: _____
86: .d88888888bo.
87: .d8888888888888b.
88: 8888888888888888b
89: 888888888888888888
90: 888888888888888888
91: Y8888888888888888
92: ,od888888888888888888P
93: .'`Y8P'```'Y8888888888P'
94: .'_ ` _ 'Y88888888b
95: / _` _ ` Y88888888b ____
96: _ | / \ / \ 8888888888.d888888b.
97: d8b | | /| | /| 8888888888d8888888888b
98: 8888_\ \_|/ \_|/ d888888888888888888888b
99: .Y8P `'-. d88888888888888888888888
100: / ` ` `Y8888888888888888
101: | __ 888888888888888P
102: \ / ` dPY8888888888P'
103: '._ .' .' `Y888888P`
104: `"'-.,__ ___.-' .-'
105: jgs `-._```` __..--'`
106:
107: */
108:

You might also like