hi there, i do hope someone can help with my delima. yes this is homeowork but i am 80% through my program and only wish to get some guidance on my program.
my program has a number of things it has to do and one the things i am having trouble with is being able to read a text file with x and y points in it and then use those points to display a XY Canvas plot. i have got the plot working with user input points but cannot get it to read a file.
this is my canvas XY plot code (without the user defining the values for x and y):
int i, j, x, y;
char plot[21][75] = {'.'};
plot[x][y]='+';
i need help with selecteing a file from a list which i have only allowed the circle option to be selected but to keep things easy for now my text file only has a few random points not a whole circle. the text file just looks like this:
13 5
3 4
18 60
where 13 is the row and 5 is the column. Heres the full code minus the the functions that are not needed:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <locale>
using namespace std;
int inputFile();
const int row=21;
const int col=75;
int main()
{
int choice;
cout<<endl<<"XY Plotter"; //Heading to program
cout<<endl<<"--------------------------------------------------";
cout<<endl<<"1. Display XY Plot\n";
cout<<"2. Read Input From File\n";
cout<<"3. Read Input From Keyboard\n";
cout<<"4. Clear XY Canvas\n";
cout<<"5. Scale / Shift Figure\n";
cout<<"6. Quit Program\n"<<endl;
cout<<"Make A Selection From The Menu: ";
cin>>choice; //Input selection made by user
if (choice==2)
{
inputFile();
}
return 0;
}
int inputFile()
{
int choice2, file;
cout<<endl<<"\t**You Have Selected To Read From A File**\n"<<endl;
cout<<"Please Choose From The Following:";
cout<<"\n--------------------------------"<<endl;
cout<<"1. Enter a file name: "<<endl;
cout<<"2. Select file from a list"<<endl;
cout<<"3. Return To Main Menu"<<endl;
cout<<endl<<"Make A Selection From The Menu: ";
cin>>choice2;
if (choice2==2)
{
cout<<endl<<"*Please Select One Of The Following:"<<endl;
cout<<"1. A Circle"<<endl;
cout<<"2. A Square"<<endl;
cout<<"3. A Triangle"<<endl;
cout<<endl<<"Make A Selection From The Menu: ";
cin>>file;
cout<<"\n";
if(file==1)
{
ifstream File;
File.open("c\\temp\\sample.txt");
int i, j, x, y;
File>>x>>y;
ah just realised tha by cutting it short it doesnt work, here is my full code where if(file==1) is where i am having my problem:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <locale>
using namespace std;
int canvas();
int inputFile();
int inputKeyboard();
void clear();
void scaleShift();
int quit();
const int row=21;
const int col=75;
int main()
{
int choice;
cout<<endl<<"C++ Assignment 2 Tim Gradden 16519448 - XY Plotter"; //Heading to program
cout<<endl<<"--------------------------------------------------";
cout<<endl<<"1. Display XY Plot\n";
cout<<"2. Read Input From File\n";
cout<<"3. Read Input From Keyboard\n";
cout<<"4. Clear XY Canvas\n";
cout<<"5. Scale / Shift Figure\n";
cout<<"6. Quit Program\n"<<endl;
cout<<"Make A Selection From The Menu: ";
cin>>choice; //Input selection made by user
if (choice==1)
{
canvas();
}
if (choice==2)
{
inputFile();
}
if (choice==3)
{
inputKeyboard();
}
if (choice==4)
{
clear();
}
if (choice==5)
{
scaleShift();
}
if (choice==6)
{
quit();
}
return 0;
}
int canvas ()
{
int i, j;
char plot[21][75] = {'.'};
cout<<endl<<"\t**You Have Selected To Read From A File**\n"<<endl;
cout<<"Please Choose From The Following:";
cout<<"\n--------------------------------"<<endl;
cout<<"1. Enter a file name: "<<endl;
cout<<"2. Select file from a list"<<endl;
cout<<"3. Return To Main Menu"<<endl;
cout<<endl<<"Make A Selection From The Menu: ";
cin>>choice2;
if(choice2==1)
{
char fileName;
cout<<"Please Enter The File Name: ";
cin>>fileName;
}
if (choice2==2)
{
cout<<endl<<"*Please Select One Of The Following:"<<endl;
cout<<"1. A Circle"<<endl;
cout<<"2. A Square"<<endl;
cout<<"3. A Triangle"<<endl;
cout<<endl<<"Make A Selection From The Menu: ";
cin>>file;
cout<<"\n";