6G Celicas Forums

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Help me with my C++ assignment :(, functions wtf?
post Oct 13, 2009 - 11:59 PM
+Quote Post
Mstoochn

Enthusiast
***
Joined Apr 27, '09
From West Coast Canada
Currently Offline

Reputation: 0 (0%)




#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

int main()
{
//declared values/strings/vectors
int choice;
ifstream inFile;
ofstream outFile;
string strFName, strLName;
string strFileName;
vector<string> vecStudent;
//ask for file name
cout<<"Please enter the data file name (with location): ";
cin >> strFileName;
//open input file
inFile.open(strFileName.c_str());
//error check file name
if (inFile.fail())
{
cout<<"Input file error!"<<endl;
return -1;
}
do{
//main menu
cout<<"----------------------------------------"<<endl;
cout<<"Grade Report Program - Main Menu"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"Enter 1 to display ALL students"<<endl;
cout<<"Enter 2 to add a student name"<<endl;
cout<<"Enter 3 to delete a student name"<<endl;
cout<<"Enter 4 to modify a student name"<<endl;
cout<<"Enter 5 to sort the names by First Name"<<endl;
cout<<"Enter 6 to SAVE and quit the program"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"Enter menu option: ";
cin>>choice;

if(choice == 1 ){
//read the names from input file into vector
while (inFile >> strFName >> strLName)
vecStudent.push_back(strFName+" "+strLName);
inFile.close();
//display the content of the vector
cout<<"Display ALL student names.."<<endl;
for (int i=0; i<vecStudent.size(); i++){
cout <<vecStudent[i]<<endl;
}
cout<<"---- A total of "<<vecStudent.size()<<" names ----"<<endl;
}else if(choice == 2 ){
//add a new name
cout<<endl<<"Enter a new name (First and Last Name): ";
cin>>strFName>>strLName;
vecStudent.push_back(strFName+" "+strLName);
cout<<"---- Name "<<strFName<<" " <<strLName<<" has been added ----"<<endl;
//functions not yet covered IGNORE THEM
}else if(choice == 3 )
cout<<"Function 3 Has Not Yet Been Added"<<endl;
else if(choice == 4 )
cout<<"Function 4 Has Not Yet Been Added"<<endl;
else if(choice == 5 )
cout<<"Function 5 Has Not Yet Been Added"<<endl;
else if(choice == 6 ){
//open output file for writing/saving
outFile.open(strFileName.c_str());
if (outFile.fail())
{
cout<<"Output file error!"<<endl;
return -1;
}
cout<<"Thanks for using the program. Program terminated"<<endl;
//save vector to output file
for (int i=0; i<vecStudent.size(); i++)
outFile <<vecStudent[i]<<endl;
outFile.close();
return 0;
}else
cout<<"Invalid. Choose again"<<endl;
}while(choice != 6);
}

This post has been edited by Mstoochn: Nov 9, 2009 - 10:28 PM
post Oct 15, 2009 - 6:10 PM
+Quote Post
SlvrCelica09



Enthusiast
***
Joined Jan 10, '09
From Burtonsville, Maryland
Currently Offline

Reputation: 1 (100%)




Mike, have you done your studying? code is rather easy.. check out dreamincode.net.. Btw.. try using a case statement. MUCH easier.


--------------------
THIS IS WHERE WE HOLD THEM!
Still trying to find the cure for ST205 asthma..
6gc.net's outlaw vigilante because im a LEADER not a follower.
post Oct 15, 2009 - 6:25 PM
+Quote Post
mmmchocolate



Enthusiast
***
Joined Nov 18, '08
From Idaho
Currently Offline

Reputation: 1 (100%)




wtf


--------------------
A work in (extremely slow) progress
post Oct 15, 2009 - 6:37 PM
+Quote Post
nics



Enthusiast
*****
Joined Feb 15, '08
From Royal Oak, MI
Currently Offline

Reputation: 7 (100%)




its been a while... i only remember printf and scanf and arrays...


--------------------
God made man....
Everything else...
Made in China

post Oct 15, 2009 - 6:49 PM
+Quote Post
SlvrCelica09



Enthusiast
***
Joined Jan 10, '09
From Burtonsville, Maryland
Currently Offline

Reputation: 1 (100%)




QUOTE (nics @ Oct 15, 2009 - 6:37 PM) *
its been a while... i only remember printf and scanf and arrays...


I believe thats Java statements


--------------------
THIS IS WHERE WE HOLD THEM!
Still trying to find the cure for ST205 asthma..
6gc.net's outlaw vigilante because im a LEADER not a follower.
post Oct 15, 2009 - 7:03 PM
+Quote Post
SlvrCelica09



Enthusiast
***
Joined Jan 10, '09
From Burtonsville, Maryland
Currently Offline

Reputation: 1 (100%)




im not quite sure what the goal is for your program.. do you want the user to just input 1 grade or more than one?

if more than one, you need your program to gather all user data.. and this is where its tricky b/c im sure if you are assuming all grades are out of 100. Explain to me exactly what your program needs to do so I can further assist you.

QUOTE (Mstoochn @ Oct 13, 2009 - 11:59 PM) *
basic idea is the reorganis the average calculator so its not in the main function, and to add a function for a letter grade


#include <iostream>
using namespace std;

string letter_grade (double grade);
double calcaverage (double count, double grade);

int main(){

int i = 0; //---Declared Values
double grades[1000];
double average = 0;
double highest = 0;
double lowest = 100;

//you need to include this in your program if you want the grade letter displayed

if (grade <= 59)
grade = 'F';
if (grade <= 69 && grade >= 60)
grade = 'D';
if (grade <= 79 && grade>= 70)
grade = 'C';
if (grade <= 89 && grade>= 80)
grade = 'B';
if (grade >= 90 && grade <= 100)
grade = 'A';



while(grades[i-1] != -1 ){ //---While loop until
cout<<"Enter your Grades:"<<endl; //--- -1 is chosen
cin >> grades[i];
if(grades[i] < 60)
cout<<"You Failed! "<<endl; [b]do you want to display the user entry here? << grades; [/b]
else
cout<<"You Pass! "<<endl; add the letter grade function here

if(grades[i] > 100 || grades[i] < -1 ){ //---Error Test -2 > grade < 100
cout << "Invalid grade" << endl;
}else{
if(grades[i] == -1) //---end sequence if grade -1
break;
else{
if(grades[i] > highest){ //---Create high grade value
highest = grades[i];
}
if(grades[i] < lowest){ //---Create lowest grade value
lowest = grades[i];
}
average = average + grades[i];
i++;
}
}
}
average = average / i; make calcaverage function work here
cout << "lowest: " << lowest << endl;
cout << "highest: " << highest << endl;
cout << "average: " << average << endl;
return 0;
}

string letter_grade (double grade){
if (grade >= 80) return "A";
if (grade >= 70) return "B";
if (grade >= 60) return "C";
if (grade <= 50) return "U";
return "";
}

double calcaverage(double count, double grade){
double avg;
avg = grade / count;
return avg;
}


let me know the goal

This post has been edited by SlvrCelica09: Oct 15, 2009 - 7:04 PM


--------------------
THIS IS WHERE WE HOLD THEM!
Still trying to find the cure for ST205 asthma..
6gc.net's outlaw vigilante because im a LEADER not a follower.
post Oct 15, 2009 - 8:10 PM
+Quote Post
nics



Enthusiast
*****
Joined Feb 15, '08
From Royal Oak, MI
Currently Offline

Reputation: 7 (100%)




QUOTE (SlvrCelica09 @ Oct 15, 2009 - 4:49 PM) *
QUOTE (nics @ Oct 15, 2009 - 6:37 PM) *
its been a while... i only remember printf and scanf and arrays...


I believe thats Java statements


my mistake its just plain turbo C


--------------------
God made man....
Everything else...
Made in China


Reply to this topicStart new topic
4 User(s) are reading this topic (4 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: December 4th, 2024 - 8:11 PM