I am currently writing a program which works out student marks and outputs the passes and fails two files. I have written some code but it does seem work as no names are displayed and according to this everybody has passed. My switch function is working, so why dont the other functions work? I have been creating new constructors, adding to the student class and allsorts but I just keep getting errors. My code is below -
#include <cstdlib>
-
#include <iostream>
-
#include <fstream>
-
#include <string>
-
using namespace std;
-
-
//This is the class definition of student
-
-
class Student
-
{
-
public:
-
Student();
-
Student(string n, int y, int m1, int m2);
-
int getYear(){return year;}
-
double getOverallMark();
-
string getformatName();
-
bool getpassed();
-
static int GetCountPasses();
-
static int GetCountFails();
-
-
-
private:
-
string studentName;
-
int mark1;
-
int mark2;
-
int year;
-
string studentFName;
-
string studentSurname;
-
string name;
-
double overallMark;
-
static int CountPasses();
-
static int CountFails();
-
string formatName();
-
bool passed();
-
-
};
-
-
// Default constructor of the Student Class
-
Student::Student ()
-
{
-
studentName = "";
-
mark1 = 0;
-
mark2 = 0;
-
year = 0;
-
}
-
-
// This is the constructor of the student class
-
Student::Student (string n, int y, int m1, int m2)
-
{
-
studentName = n;
-
mark1 = m1;
-
mark2 = m2;
-
year = y;
-
}
-
-
-
//Function prototype for menuselect
-
char menuselect();
-
-
//MenuSelect function
-
char menuselect()
-
{
-
char menusel;
-
char userchoice;
-
cout << "Display the student with the overall highest mark (H) or lowest overall mark (L)" << endl;
-
cin >> menusel;
-
-
if (menusel == 'H' || menusel == 'h')
-
-
{
-
userchoice = 'H';
-
}
-
-
else if (menusel == 'L' || menusel == 'l')
-
-
{
-
userchoice = 'L';
-
}
-
return userchoice;
-
}
-
-
-
// This is the major part of the program
-
int main ()
-
{
-
string studentFName;
-
string studentSurname;
-
string student_Name;
-
int yearStudy;
-
int mark1;
-
int mark2;
-
char userChoice;
-
-
userChoice = menuselect();
-
ifstream markfile;
-
markfile.open("student_marks.txt");
-
if ( markfile.fail ())
-
-
{
-
cout << "There is an error in opening the file." << endl;
-
cout << "The program will now close!" <<endl;
-
exit(1);
-
}
-
-
ofstream passes;
-
passes.open("pass.txt");
-
ofstream fails;
-
fails.open("fail.txt");
-
-
while ( ! markfile.eof())
-
-
{
-
markfile >> studentFName >> studentSurname >> yearStudy >> mark1 >> mark2;
-
cout << "I'm in the code!" << " " << studentFName << " " << studentSurname << " "<< yearStudy << " " << mark1 << " " << mark2;
-
student_Name = studentFName + " " + studentSurname;
-
Student s1(student_Name, yearStudy, mark1, mark2);
-
-
-
string propname;
-
double mark;
-
bool passed;
-
-
propname = s1.getformatName();
-
mark = s1.getOverallMark();
-
passed = s1.getpassed();
-
-
-
-
if (passed = 1)
-
{
-
passes << propname << " " << mark << " " << "PASS" << endl;
-
}
-
else if (passed = 0)
-
{
-
fails << propname << " " << mark << " " << "FAIL" << endl;
-
}
-
}
-
markfile.close();
-
passes.close();
-
fails.close();
-
return 0;
-
}
-
-
-
double Student::getOverallMark()
-
{
-
switch (year)
-
{
-
-
case 1 :
-
overallMark = static_cast<double>((mark1+mark2)/2);
-
break;
-
-
case 2 :
-
overallMark = static_cast<double>((mark1 * 0.4) + (mark2 * 0.6));
-
break;
-
-
case 3 :
-
overallMark = static_cast<double>((mark1 * 0.3) + (mark2 * 0.7));
-
break;
-
-
default:
-
cout << "There is an error somewhere, program will now close!!!" << endl;
-
exit(1);
-
}
-
return overallMark;
-
}
-
-
-
-
string Student::getformatName()
-
{
-
string f;
-
string s;
-
string i;
-
string name;
-
-
f = "David";
-
s = "Lee";
-
-
name = f + " " + s;
-
-
i = f.substr(0,1);
-
-
name = s + " ," + i + ".";
-
-
return name;
-
}
-
-
-
-
bool Student::getpassed()
-
{
-
if(overallMark >= 40)
-
return true;
-
else
-
return false;
-
}
-
-
-
-
-
Any help would be appriacited as I have been trying how to work out this problem for hours but to no avail.
7 1967 Savage 1,764
Recognized Expert Top Contributor
By no names are displayed,you mean nothing is written to file,or nothing is outputted with cout,or both?
Ignore the cout statments, I just put them there to see if the code is working, and I do get an output to screen. What I meant was that there are no names in the files but the comma and full stop is in the files so the function must be working but no data must be getting passed to it.
Savage 1,764
Recognized Expert Top Contributor
Have you couted: - propname = s1.getformatName();
-
mark = s1.getOverallMark();
-
passed = s1.getpassed();
,to see what is in these variables?
If I do that I get errors including 'getFormatName' undeclared (first use this function)
Savage 1,764
Recognized Expert Top Contributor
If I do that I get errors including 'getFormatName' undeclared (first use this function)
Perhaps you puted getFormatName instead of getformatName,o r if is this just a posting error move getformatName declaration to some place before main.
What do you mean by the get format name declaration? and how do I pass data into the function. I want getFormatName to use studentFName and studentSurname.
sicarie 4,677
Recognized Expert Moderator Specialist
howmanymiles-
You are having very basic issues with C++ that we are not going to be able to help you with easily. As the language is case-sensitive, there is a difference between get formatName() and get FormatName(). The use of a capital F in one is referencing a completely different function.
Please read a tutorial such as this or your class' reading materials thoroughly before posting again. You're missing key conceptual elements that will take a very long time for us to explain.
That is a very good tutorial site, if you look through the others, you will probably find several things you didn't know before...
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Amr Mostafa |
last post by:
Hello :)
I'm trying to write a script that deals with a web service.
I'm using NuSoap class.
my question is : Can I pass some variables By Reference to the web
service and get the result back in my variables ??
note1: I'm not the one who wrote the web service.. so I can't modify
|
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of code...
TCHAR myArray;
DoStuff(myArray);
|
by: Steve Turner |
last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows:
typedef struct tag_scanparm
{
short cmd;
short fdc;
WORD dsf;
short boxcar;
short average;
short chan_ena;
|
by: John Pass |
last post by:
Hi,
In the attached example, I do understand that the references are not changed
if an array is passed by Val. What I do not understand is the result of line
99 (If one can find this by line number) which is the last line of the
following sub routine:
' procedure modifies elements of array and assigns
' new reference (note ByVal)
Sub FirstDouble(ByVal array As Integer())
Dim i As Integer
|
by: Jake Thompson |
last post by:
Hello I created a DLL that has a function that is called from my main c
program.
In my exe I first get a a pointer to the address of the function by
using GetProcAddress and on the dll side I make sure that my function
is being exported by adding a line to the .def file.
This seems to work because when I debug it recognizes the dll and once
it hits the function it goes right into the proper location of the dll.
| |
by: Andrew Bullock |
last post by:
Hi,
I have two classes, A and B,
B takes an A as an argument in its constructor:
A a1 = new A();
B b = new B(a1);
|
by: TS |
last post by:
I was under the assumption that if you pass an object as a param to a method
and inside that method this object is changed, the object will stay changed
when returned from the method because the object is a reference type?
my code is not proving that. I have a web project i created from a web
service that is my object:
public class ExcelService : SoapHttpClientProtocol
{
|
by: Hakan Örnek |
last post by:
Hi ,
I want to parameter passing to my windows sevice. I call service commands
like this ;
'------------------------------------------------------------
Dim sc As ServiceController
sc = New ServiceController("ProsetLogServices")
sc.MachineName = "."
If sc.Status = ServiceControllerStatus.Stopped Then
sc.Start()
End If
|
by: S. |
last post by:
Hi all,
Can someone please help me with this?
I have the following struct:
typedef struct {
char *name;
int age;
} Student;
|
by: John Sheppard |
last post by:
Hello there I was wondering if anyone could help me,
I am trying to pass a typed dataset to a dialoged child form by reference.
I have binding sources sitting on the child form. So to refresh them I just
set their datasource. I am guessing this is probably what is causing the
problem. Is there a better way to do this?
Anyway this all works happily and things show up when the record already
exists but I have 2 problems ;
1) When I add...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |