Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 10-14-2005, 08:58 PM   #1 (permalink)
Cro
Registered User
 
Join Date: Oct 2005
Posts: 5
OS: XP


C++ help with arrays..

hi guys. im really having probs with arrays. Basically i open an input file like:

Code:
ifstream infile;

infile.open("A:\\students.txt");
now the file contains different int numbers...like:

76,89,150,135,200,76,12,100,150,28,178,189,167,200,175,150,87,99,129,149,176,200,87,35,157,189

now what i need to do is to put all those in an array...and then determine the number of students having scroes in each of the following ranges:

0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, and 175-200.

it should then display the results like:

------------COUNTS(the total number)
0-24 ------- 1
25-49-------- 2
50-74 --------0
.. ----------- .
. ----------- .
.. ----------- .
.

please if someone could help me.... thanks!

ive tried some code, but im really stuck:,, this is what ive done:

Code:
int list[26];
	int z;
	
	infile >> list[26];
	while(infile)
	{
		///for(z = 0; z < 26; z++)
		//{
			
			if(list[z] > 0 && list[z] < 25)
			{
				list[z]++;
				sum = sum + list[z];
				
				
			}
		infile >> list[26];
		cout << sum;
	}
Cro is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 10-15-2005, 10:30 PM   #2 (permalink)
Registered User
 
Join Date: Oct 2005
Posts: 4
OS: XP Prof


Binary Search or Bubble Sort?

Have you tried something like this?

Example of Binary Seach.....

int binarysearch (int array[], int size, int searchKey)

{

int low = 0, middle, high;

high = -1;

while (low <= high);

{

middle = (low + high) / 2;

if (searchKey == array [middle])
return middle;

else if (searchKey < array [middle])
high = middle -1;

else
low = middle + 1;

}

return -1; //not found

}

Does this help? Once it finds the values in the array you should be able to sort them with some more code.
Cwwoods is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-16-2005, 04:33 AM   #3 (permalink)
TSF Enthusiast
 
Join Date: Dec 2004
Posts: 604
OS: windows xp


PHP Code:
#include <iostream> 
#include <fstream> 
#include <iomanip>

using namespace std

int main() 

    
int n[26];
    
    
ifstream input;  
    
input.open("input.dat"); 
    
    if(
input.fail( ))
    { 
       
cout << "Cannot open file"<<endl
       return 
1
    } 

    
int x=0;
    
    while(!
input.eof())
    {
        
input>> n[x];
        
x++;
    }

    
input.close( );
    
    
int y=25;
    
int size=0;
    
cout<<setw(3)<<"Range"<<setw(9)<<"count"<<endl<<endl;
    for(
int a=0;a<8;a++)
    {
        
int z=0;
        while(
z<x)
        {
            if(
n[z]<&& n[z]>y-25)
            {
                
size++;
            }
            
            
z++;
            
        }
        
        
cout<<setw(3)<<y-25<<setw(2)<<"-"<<setw(3)<<y<<setw(3)<<size<<endl;
        
size=0;
        
y=y+25;
    }
    
            
    return 
0;

This will work. basically what it does it save each value in the file into a array. then it searchers the array 8 times each time looking for a different one of the ranges you needed then displays how many time it found a number in that range.
__________________
mgoldb2 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 11-05-2005, 06:27 PM   #4 (permalink)
Cro
Registered User
 
Join Date: Oct 2005
Posts: 5
OS: XP


thanks for all the help :) very much appreciated!
Cro is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 07:06 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85