Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6771479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:26:14+00:00 2026-05-26T15:26:14+00:00

#include <iostream> #include <math.h> #include <cstdlib> using namespace std; void circle(int x, int y,

  • 0
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;

void circle(int x, int y, int radius);
void line(int a, int b, int c, int d);
bool buffer[26][81];
char drawSpace[26][81];

int main() {
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    int x = 0;
    int y = 0;
    int radius = 0;
    char choice;

    cout << "Type 'c' to draw a circle or type 'l' to draw a line." << endl;
    cin >> choice;

    if (choice == 'c'){
        cout << "please enter an x coordinate for the center of the circle \n";
        cin >> x;
        cout << "please enter a y coordinate for the center of the circle \n";
        cin >> y;
        cout << "please enter a value for the radius of the circle \n";
        cin >> radius;
        int moves = (x - radius) / 10;
        for (int s = 0; s < moves; s++){
            circle(x, y, radius);
            system("clear");
            x = x -10;
        }
    }

    else if (choice == 'l'){
        cout << "Please enter the x coordinate for the first point on the line \n";
        cin >> a;
        cout << "Please enter the y coordinate for the first point on the line \n";
        cin >> b;
        cout << "Please enter the x coordinate for the end point on the line \n";
        cin >> c;
        cout << "Please enter the y coordinate for the end point on the line \n";
        cin >> d;
    }

    else
        cout << "you did not enter an appropriate letter, please restart the program and try again."<< endl;

    return 0;
}

void circle(int x, int y, int radius){
    if (x + radius >= 81|| x - radius <= 0 || y + radius >= 26 || y - radius <= 0){
        cout << "the coordinates provided for the circle will not fit on the screen" << endl;
        return;
    }

    for (int i = 0; i < 26; i++) {
        for(int j = 0; j < 81; j++) {
            int a = abs (x - j);
            int b = abs (y - i);
            int distance =  pow(a, 2) + pow(b, 2);
            int realDistance = pow(radius, 2);
            if (abs(realDistance - distance) <= 3){
                buffer[i][j] = true;
            }
        }
    }

    for (int m = 0; m < 26; m++){
        for(int n = 0; n < 81; n++){
            if (buffer[m][n]){
                drawSpace[m][n] = 42;
            }
            else
                drawSpace[m][n] = 32;
        }
    }

    for (int row = 25; row >= 0; row--) {
        for (int col = 0; col < 81; col++) {
            cout << drawSpace[row][col];
        }
        cout << "\n";
    }
}

void line(int a, int b, int c, int d){
    if (a >= 81 || c >= 81 || a <= 0 || c <= 0 || b >= 26 || d >= 26 || b <= 0 || d <= 0){
        return;
    }
    int intercept = 0;
    double rise = d - b;
    double run = c - a;
    double slope = rise/run;
    intercept = b - (slope*a);
    for (int i = 0; i < 26; i++) {
        for(int j = 21; j < 81; j++) {
            if (slope > 0){
                if (j > a && j < c){
                    int newIntercept = i - (slope*j);
                    int test = abs (intercept - newIntercept);
                    if (test <= 0)
                        buffer[i][j] = true;
                else
                    buffer[i][j] = false;
                }
            }
            else if (slope < 0){
                if (j < a && j > c){
                    int newIntercept = i - (slope*j);
                    int test = abs (newIntercept - intercept);
                    if (test <= 0)
                        buffer[i][j] = true;

                }
                else
                    break;
            }
        }
    }

    for (int m = 0; m < 26; m++){
        for(int n = 0; n < 81; n++){
            if (buffer[m][n])
                drawSpace[m][n] = 42;
            else
                drawSpace[m][n] = 32;
        }
    }

    for (int row = 25; row >= 0; row--) {
        for (int col = 0; col < 81; col++) {
            cout << drawSpace[row][col];
        }
        cout << "\n";
    }
}

I have written this code for a programming assignment, the goal of which is to take inputs for the coordinates and dimensions of a circle or line, and to print them out to the terminal as if it were a graph. The second step is to get the shape to move from the right side of the screen to the left. I have started to write this code for the circle, however for some reason the system(“clear”) call does not seem to clear the screen, and it simply prints extra circles without getting rid of the older one. If someone could help I would really appreciate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:26:14+00:00Added an answer on May 26, 2026 at 3:26 pm

    The original poster doesn’t have enough rep yet, so I’m posting this here for him:

    I was actually a bit off base. The system("clear") I was using actually did
    work, the problem I was encountering was that I did not reset the bool
    array I was using to plot out the points that needed to be drawn.
    Thanks for the help, I learned a few things about how to clear the screen before I found my own problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<iostream> using namespace std; class A { int a; int b; public: void eat()
#include <iostream> #include <math.h> using namespace std; int main() { int arraylength; int lastbig
#include <iostream> using namespace std; int main() { double u = 0; double w
#include <iostream> #include <vector> using namespace std; int main() { vector< vector<int> > dp(50000,
#include <iostream> #include <string> #include <fstream> using namespace std ; string strWord( int index
edit: I am implementing an algorithm in c++. #include<iostream> #include<math.h> #include<string> using namespace std;
my code: #include <iostream> using namespace std; int main() { int n=5; int a[n][n];
Please let us consider following code: #include <iostream> using namespace std; union{ int i;
#include <iostream> using namespace std; class Base { public: Base(){cout <<Base<<endl;} virtual ~Base(){cout<<~Base<<endl;} virtual
#include <iostream> using namespace std; // This first class contains a vector and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.