473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

file program

2
i want to get code for a program in visual c++ where :
1]take the name of directory say DIR
2]get a file ,say IN from that directory which has 3 column (say X, Y and Z) and many rows( display this if asked to !!)..[Also get all the files ifwhich we ask for ]
3]want an output file,say OUT, where X and Y are interchanged i.e above 'X' values in'Y' and 'Y' values in 'X'..but 'Z' remain same( and display if asked to!!)
4]get average of values(sum of numbers/number of items) in column Z and disply
5]get the total number of cells in Z more than and less than a given number 'n'
i want evrything to be displayed as a nx3 matrix

thats all.
thank you..

[input fille is table]
The CODE i have written is this:


#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>

const int maxrows = 40;//[ can i make it more..i mean vary with different files taken as input?? like dynamic memmory]
const int maxcols = 3;

void getdata(int table[][maxcols]);

void columnavg(const int table[][maxcols], float colavg[]);

void colsort(const int table[][maxcols], int sort[]);

void printarray(const int table[][maxcols], const float colavg[],
const int sort[]);

int main(void)
{

int table[maxrows][maxcols];

float colavg[maxrows] = {0};
int sort[maxrows] = {0};

getdata (table);
columnavg (table, colavg);
colsort (table, sort);
printarray (table, colavg, sort);

return 0;

}

/* ============================getdata=============== =========*/
void getdata(int table[][maxcols])
{

int row;
int col;
ifstream input;

input.open("scores.dat");

if(!input)
{

cerr << "Error opening file scores.dat\n";
exit (100);

}

for (row = 0; row < maxrows; row++)
for (col = 0; col < maxcols; col++)
{
input >> table[row][col];
}
return;
}

/* ==========================columnavg=============== =========*/
void columnavg(const int table[][maxcols], float colavg[])
{

int row;
int col;

for (col = 1; col < maxcols; col++)
{
for (row = 0; row < maxrows; row++)
colavg[col] += table[row][col];
colavg[col] /= maxrows;
}
return;

}

/* ============================colsort=============== ==========*/
void colsort(const int table[][maxcols], int sort[])
{

int row;
int col;
int walker;
int temp;
int min;
int max;

/* NEED HELP HERE, I need to find the max and min numbers in the last i.e 3rd column, the number of values that comes more than and less than number 1981 and how many are there such..
*/

return;

}

/* ===========================printarray============= ==========*/
void printarray(const int table[][maxcols], const float colavg[])
{

int row;
int col;

for (row = 0; row < maxrows; row++)
{
for (col = 0; col < maxcols; col++)
cout << setw(7) << table[row][col];
cout << endl;
}

for (col = 1; col < maxcols; col++)
cout << setw(7) << colavg[col];

return;
Oct 16 '06 #1
0 1821

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Hal Vaughan | last post by:
I want to have a config file for my program, which means I need to know where the config file is. If I type: java myclass and it runs myclass.class, is there any way to obtain the location of...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
3
by: Joe Costa | last post by:
I have written the following code to search for the right file depending on the startup file for "Client Access". The menu database that I made will load the correct config file specific for each...
6
by: Kiran | last post by:
Hi, I have program, which opens file at the startup and logs error messages to the file, file handle is closed at the end of the program. However if file is deleted in-between, program do not...
4
by: Frank | last post by:
Could someone tell me how to open a file at run time that I didn't know the name of at compile time? I know how to open a file at compile time when I know what the name is going to be. FILE...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
3
by: SpIcH | last post by:
Hi All, This is all about protecting my data in Executable file. I have developed a program in Visual Basic .NET 2002. I have many questions in mind... please help me to complete my project. ...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
5
by: mmcd79 | last post by:
I built a VB.net application that makes use of a machine level DB connection string setting, and a user level starting location setting. The machine level setting and the default user based...
0
by: Filemaxor | last post by:
I have gotten my code to be able to allow people to add new text to a .txt document and able to call up files so the user can see whats in it. The problem i'm having is getting the for loop to work...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.