GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Oct-2004, 20:22
Grid Grid is offline
New Member
 
Join Date: Oct 2004
Posts: 3
Grid is on a distinguished road

C++ help


Hey guys, can anyone look at my code. Im having some problems with it. 1. It will not output to a text file, 2. It will not perform the calculation, 3. The Letter Grade wont show. I tried everything I know, I'm knew at this. And can some explain what pass by reference mean. Thanks in advance.

OKEY, I got MY PROGRAM UPLOADED.
Attached Files
File Type: doc C++ Program.doc (41.5 KB, 72 views)
  #2  
Old 25-Oct-2004, 20:29
small_ticket small_ticket is offline
Junior Member
 
Join Date: May 2004
Posts: 45
small_ticket is on a distinguished road
yes we can look at your code but where is your code? :-)
  #3  
Old 25-Oct-2004, 21:42
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Grid
Hey guys, can anyone look at my code. Im having some problems with it. 1. It will not output to a text file, 2. It will not perform the calculation, 3. The Letter Grade wont show. I tried everything I know, I'm knew at this. And can some explain what pass by reference mean. Thanks in advance.
Not if you don't post it. My psychic helmet is on the fritz!

When you do post it, please use code tags! Instructions are on the site where new posters are supposed to find them.
__________________

Age is unimportant -- except in cheese
  #4  
Old 25-Oct-2004, 21:44
Grid Grid is offline
New Member
 
Join Date: Oct 2004
Posts: 3
Grid is on a distinguished road
Quote:
Originally Posted by WaltP
Not if you don't post it. My psychic helmet is on the fritz!

When you do post it, please use code tags! Instructions are on the site where new posters are supposed to find them.

Im new to C++ so any help you can give me Id appreciate it. Thanx
  #5  
Old 25-Oct-2004, 21:46
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Grid
Hey guys, can anyone look at my code. Im having some problems with it. 1. It will not output to a text file, 2. It will not perform the calculation, 3. The Letter Grade wont show. I tried everything I know, I'm knew at this. And can some explain what pass by reference mean. Thanks in advance.

OKEY, I got MY PROGRAM UPLOADED.
Not good. DOC files are not compilable. You really should post appropriate sections of your code here and explain in detail
1) what the code is supposed to do
2) what it actually does
3) where you think the problem is
You can also place comments on the lines of code you're having trouble with, making it easy on us to figure out the problem.
__________________

Age is unimportant -- except in cheese
  #6  
Old 25-Oct-2004, 21:57
crystalattice's Avatar
crystalattice crystalattice is offline
Flame War Instigator
 
Join Date: Apr 2004
Location: San Diego
Posts: 1,550
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Pass by reference


Quote:
Originally Posted by Grid
Hey guys, can anyone look at my code. Im having some problems with it. 1. It will not output to a text file, 2. It will not perform the calculation, 3. The Letter Grade wont show. I tried everything I know, I'm knew at this. And can some explain what pass by reference mean. Thanks in advance.
As we wait for your code, I'll try and explain pass by reference. When passing values into/out of functions, the default is to pass a copy of the value (pass by value).
CPP / C++ / C Code:
int num;
void doSomething(int num);
This function takes a copy of the integer num and does something to it. The original integer is never touched.

When you use pass by reference, the actual address of the value in memory is given to the function, allowing the function to do whatever it wants to the original value.
CPP / C++ / C Code:
void doSomethingElse(int& num);
//The address of num is used as an argument, not a copy of the number
This means you have to be careful if you want to keep the original value.

The main places I've seen this is when you are using large values (structures, classes, arrays, etc.) that could be too large to effectively make a copy every time. If you're returning multiple values from the function, then you would also use PBR.
CPP / C++ / C Code:
int doSomething(int num1, int num2, int num3);
//This function can take as many arguments as you want, but can only
//return one value

void doAnother(int& num1, int& num2, int& num3);
//This function would modify the data at the addresses for each integer,
//hence, all three numbers would be effectively returned from the 
//function.

Hope that helps.
__________________
Common Sense v2.0-Striving to make the world a little bit smarter.
  #7  
Old 25-Oct-2004, 22:13
Grid Grid is offline
New Member
 
Join Date: Oct 2004
Posts: 3
Grid is on a distinguished road
Quote:
Originally Posted by Grid
Im new to C++ so any help you can give me Id appreciate it. Thanx

Okey, basically this program is suppose to execute with functions to read student first nad last name 3 program score, 3 test scores, claculate the test average, program average course average, and gives it a letter grade. It's suppose to output to the monitor and to an output text file. But the problem is, I cant get it to output on a text file,and the calculation will not work.

I'm gonnatry to uploade my program again. Thanks.
okey, it wont let me upload using .cpp file. It onle accepts file bmp doc gif jpe jpeg jpg pdf png psd txt zip.
CPP / C++ / C Code:
//Objective: This program uses functions to read student information from
//            the keyboard and output averages and
//            grades to the monitor and to an output text file.
#include<iostream>
#include<conio>
#include<iomanip>
#include<string>       // 
#include<fstream>
using namespace std;

void header();

void prompt_info(string fname, string lname,int pscore1, int pscore2, int pscore3,int tscore1, int tscore2, int tscore3);

void header1();

void calc_info(int pscore1, int pscore2,int pscore3,int tscore1, int tscore2, int tscore3);

float calc_output(string fname, string lname, float totpoints, float progavg, float testavg, float courseavg);

void main()
{

string fname;
string lname;
int pscore1;
int pscore2;
int pscore3;
int tscore1;
int tscore2;
int tscore3;
float totpoints;
float progavg;
float testavg;
float courseavg;
char continuation_Flag = 'Y';
        do
{


        header();
        prompt_info (fname, lname, pscore1,pscore2,pscore3,tscore1,tscore2,tscore3);
        header1();
        calc_info (pscore1,  pscore2, pscore3,tscore1, tscore2, tscore3);
        calc_output(  fname, lname, totpoints,  progavg,  testavg,  courseavg );
cout<<"Please enter Y to calculate another grade or enter N to exit: ";
cin>>continuation_Flag;
system("cls");
}       while(toupper(continuation_Flag) =='Y');
        cout<<"Press a key to continue"<<endl;
        getch();
}//end of main


void header()
{

ofstream fout;
fout.open("output.txt");
   if(!fout.is_open())
   {
      cout<<"Output File Failure"<<endl;
      cout<<"Press any key to continue"<<endl;
      getch();
      return;
   }
cout<<setw(80)<<setfill('x')<<'x'<<endl;
fout<<setw(80)<<setfill('x')<<'x'<<endl;
cout<<setw(5)<<setfill(' ')<<' '<<"Objective: This program uses functions to read student information from"<<endl;
fout<<setw(5)<<setfill(' ')<<' '<<"Objective: This program uses functions to read student information from"<<endl;
cout<<setw(5)<<setfill(' ')<<' '<<"the keyboard and output averages and"<<endl;
fout<<setw(5)<<setfill(' ')<<' '<<"the keyboard and output averages and"<<endl;
cout<<setw(5)<<setfill(' ')<<' '<<"grades to the monitor and to an output text file."<<endl;
fout<<setw(5)<<setfill(' ')<<' '<<"grades to the monitor and to an output text file."<<endl;
fout<<setw(80)<<setfill('x')<<'x'<<endl;
cout<<setw(80)<<setfill('x')<<'x'<<endl;

}//End of header


void prompt_info(string fname, string lname, int pscore1,
                int pscore2, int pscore3, int tscore1,
                int tscore2, int tscore3)
{

ofstream fout;
fout.open("output.txt");
   if(!fout.is_open())
   {
      cout<<"Output File Failure"<<endl;
      cout<<"Press any key to continue"<<endl;
      getch();
      return;
   }

cout<<"Please enter the student's first and last name: ";
cin>>fname>>lname;
fout<<"Please enter the student's first and last name: ";
fout<<fname<<" "<<lname<<endl;
cout<<"Please enter the first program score: ";
cin>>pscore1;
fout<<"Please enter the first program score: ";
fout<<pscore1<<endl;;
cout<<"Please enter the second program score: ";
cin>>pscore2;
fout<<"Please enter the second program score: ";
fout<<pscore2<<endl;;
cout<<"Please enter the third program score: ";
cin>>pscore3;
fout<<"Please enter the third program score: ";
fout<<pscore3<<endl;;
cout<<"Please enter the first test score: ";
cin>>tscore1;
fout<<"Please enter the first test score: ";
fout<<tscore1<<endl;;
cout<<"Please enter the second test score: ";
cin>>tscore2;
fout<<"Please enter the second test score: ";
fout<<tscore2<<endl;;
cout<<"Please enter the third test score: ";
cin>>tscore3;
fout<<"Please enter the third test score: ";
fout<<tscore3<<endl;
cout<<setw(80)<<setfill('-')<<'-'<<endl;
fout<<setw(80)<<setfill('-')<<'-'<<endl;
cout<<setw(80)<<setfill('-')<<'-'<<endl;
fout<<setw(80)<<setfill('-')<<'-'<<endl;
} //End of Prompt_info


void header1()
{
ofstream fout;
fout.open("output.txt");
   if(!fout.is_open())
   {
      cout<<"Output File Failure"<<endl;
      cout<<"Press any key to continue"<<endl;
      getch();
      return;
   }


cout<<"Student Name"<<setw(10)<<setfill(' ')<<' '<<"Total";
fout<<"Student Name"<<setw(10)<<setfill(' ')<<' '<<"Total";
cout<<setw(5)<<setfill(' ')<<' '<<"Program";
fout<<setw(5)<<setfill(' ')<<' '<<"Program";
cout<<setw(5)<<setfill(' ')<<' '<<"Test";
fout<<setw(5)<<setfill(' ')<<' '<<"Test";
cout<<setw(8)<<setfill(' ')<<' '<<"Course";
fout<<setw(8)<<setfill(' ')<<' '<<"Course";
cout<<setw(5)<<setfill(' ')<<' '<<"Grade"<<endl;
fout<<setw(5)<<setfill(' ')<<' '<<"Grade"<<endl;
cout<<setw(22)<<setfill(' ')<<' '<<"Points";
fout<<setw(22)<<setfill(' ')<<' '<<"Points";         //cout statements
cout<<setw(4)<<setfill(' ')<<' '<<"Average";
fout<<setw(4)<<setfill(' ')<<' '<<"Average";           //will output to the screen
cout<<setw(5)<<setfill(' ')<<' '<<"Average";
fout<<setw(5)<<setfill(' ')<<' '<<"Average";
cout<<setw(5)<<setfill(' ')<<' '<<"Average"<<endl;
fout<<setw(5)<<setfill(' ')<<' '<<"Average"<<endl;
cout<<setw(80)<<setfill('=')<<'='<<endl;
fout<<setw(80)<<setfill('=')<<'='<<endl;
} //End of Header1


float totpoints;
float progavg;
float testavg;
float courseavg;
char grade;
string fname;
string lname;

void calc_info(int pscore1, int pscore2, int pscore3,
                 int tscore1, int tscore2, int tscore3)
{
float totpoints = pscore1+pscore2+pscore3+tscore1+tscore2+tscore3;
float progavg = (pscore1+pscore2+pscore3)/3;
float testavg = (tscore1+tscore2+tscore3)/3;
float courseavg = (progavg+testavg)/2;
}//End of Calc_info



float calc_output(string fname, string lname, float totpoints, float progavg, float testavg, float courseavg)
{
      if(courseavg>=90) grade='A';
      else if(courseavg>=80) grade='B';
      else if(courseavg>=70) grade='C';
      else grade='F';


        cout<<setw(11)<<left<<fname+' '+lname;
        cout<<left<<setw(11)<<setfill(' ')<<' '<<fixed<<showpoint<<setprecision(2)<<totpoints;
        cout<<left<<setw(6)<<setfill(' ')<<' '<<fixed<<showpoint<<setprecision(2)<<progavg;
        cout<<left<<setw(8)<<setfill(' ')<<' '<<fixed<<showpoint<<setprecision(2)<<testavg;
        cout<<left<<setw(8)<<setfill(' ')<<' '<<fixed<<showpoint<<setprecision(2)<<courseavg;
        cout<<left<<setw(8)<<setfill(' ')<<' '<<grade;
        cout<<setw(10)<<setfill(' ')<<' '<<endl;

      return grade;


}//End of Calc_Output
Attached Files
File Type: doc C++.doc (31.5 KB, 15 views)
Last edited by dsmith : 26-Oct-2004 at 06:49. Reason: Please use [c] & [/c] for syntax highlighting
  #8  
Old 25-Oct-2004, 22:40
crystalattice's Avatar
crystalattice crystalattice is offline
Flame War Instigator
 
Join Date: Apr 2004
Location: San Diego
Posts: 1,550
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice
Next time you post code directly in the forum, I'd recommend using the codes to format it properly. Take a look at the "sticky" discussing code posting if you need help. It makes it easier to follow, and you won't get a bunch of smiley faces in the code. :-)
__________________
Common Sense v2.0-Striving to make the world a little bit smarter.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 2) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:00.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.