473,765 Members | 2,086 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error C2228: left of '.grade' must have class/struct/union

2 New Member
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iomanip>
  5. using namespace std;
  6. const int NO_OF_STUDENTS=20;
  7. struct studentType
  8. {
  9.     string studentFName;
  10.     string studentLName;
  11.     int testScore;
  12.     char grade;
  13. };
  14. void getData(studentType sList[], int NO_OF_STUDENTS);
  15. void calculateGrade(studentType sList[], int NO_OF_STUDENTS);
  16. void printResult(const studnetType sList[], int NO_OF_STUDENTS);
  17. int main()
  18. {
  19.     studentType sList[NO_OF_STUDENTS];
  20.     getData(sList, NO_OF_STUDENTS);
  21.     calculateGrade(sList, NO_OF_STUDENTS);
  22.     printResult(sList, NO_OF_STUDENTS);
  23.     return 0;
  24. }
  25.  
  26. void getData(const studentType sList[], int listSize)
  27. {
  28.     ifstream inData;
  29.     ofstream outData;
  30.     inData.open("C:\\student.txt");
  31.     for (int i=0;i<NO_OF_STUDENTS;i++)
  32.         inData>>sList[i].studentFName>>sList[i].studentLName>>sList[i].testScore;
  33.     outData.close();
  34. }
  35.  
  36. void calculateGrade(studentType sList[], int listSize)
  37. {
  38.     for (int i=0;i<NO_OF_STUDENTS;i++)
  39.     {
  40.         switch(sList[i].testScore/10)
  41.         {
  42.         case 0:
  43.         case 1:
  44.         case 2:
  45.         case 3:
  46.         case 4:
  47.         case 5:
  48.             sList[i].grade='F';
  49.             break;
  50.         case 6:
  51.             sList[i].grade='D';
  52.             break;
  53.         case 7:
  54.             sList[i].grade='C';
  55.             break;
  56.         case 8:
  57.             sList[i].grade='B';
  58.             break;
  59.         case 9:
  60.         case 10:
  61.             sList[i].grade='A';
  62.             break;
  63.         }//closes switch
  64.     }//closes for loop
  65. }//closes function
  66.  
  67. void printResult(const studnetType sList[], int listSize) (THIS IS WHERE I'M HAVING TROUBLE
  68. {
  69.     for (int d=0;d<NO_OF_STUDENTS;d++)
  70.     {
  71.         cout<<sList[d].studentFName<<sList[d].studentLName<<sList[d].testScore<<sList[d].grade<<endl;
  72.     }
  73. }
  74.  

1>------ Build started: Project: project5, Configuration: Debug Win32 ------
1>Compiling...
1>project5.cpp
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(16) : error C2146: syntax error : missing ',' before identifier 'sList'
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(22) : error C2660: 'printResult' : function does not take 2 arguments
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(32) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 8\vc\include\is tream(1137): could be 'std::basic_ist ream<_Elem,_Tra its> &std::operat or >><std::char_tr aits<char>>(std ::basic_istream <_Elem,_Trait s> &,signed char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(1139): or 'std::basic_ist ream<_Elem,_Tra its> &std::operat or >><std::char_tr aits<char>>(std ::basic_istream <_Elem,_Trait s> &,signed char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(1141): or 'std::basic_ist ream<_Elem,_Tra its> &std::operat or >><std::char_tr aits<char>>(std ::basic_istream <_Elem,_Trait s> &,unsigned char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(1143): or 'std::basic_ist ream<_Elem,_Tra its> &std::operat or >><std::char_tr aits<char>>(std ::basic_istream <_Elem,_Trait s> &,unsigned char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\st ring(593): or 'std::basic_ist ream<_Elem,_Tra its> &std::operat or >><char,std::ch ar_traits<char> ,std::allocator <_Ty>>(std::bas ic_istream<_Ele m,_Traits> &,std::basic_st ring<_Elem,_Tra its,_Ax> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char> ,
1> _Ty=char,
1> _Ax=std::alloca tor<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(155): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(std::basic_i stream<_Elem,_T raits> &(__cdecl *)(std::basic_i stream<_Elem,_T raits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(161): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(std::basic_i os<_Elem,_Trait s> &(__cdecl *)(std::basic_i os<_Elem,_Trait s> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(168): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(std::ios_bas e &(__cdecl *)(std::ios_bas e &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(175): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(std::_Bool &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(194): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(228): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(unsigned short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(247): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(273): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(unsigned int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(291): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(309): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(__w64 unsigned long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(329): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(__int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(348): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(unsigned __int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(367): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(float &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(386): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(404): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(long double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(422): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(void *&)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\is tream(441): or 'std::basic_ist ream<_Elem,_Tra its> &std::basic_ist ream<_Elem,_Tra its>::operator >>(std::basic_s treambuf<_Elem, _Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::ch ar_traits<char>
1> ]
1> while trying to match the argument list '(std::ifstream , const std::string)'
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(67) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(67) : error C2146: syntax error : missing ',' before identifier 'sList'
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(71) : error C2065: 'sList' : undeclared identifier
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(71) : error C2228: left of '.studentFName' must have class/struct/union
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(71) : error C2228: left of '.studentLName' must have class/struct/union
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(71) : error C2228: left of '.testScore' must have class/struct/union
1>c:\documents and settings\yese\m y documents\visua l studio 2005\projects\p roject5\project 5.cpp(71) : error C2228: left of '.grade' must have class/struct/union
1>Build log was saved at "file://c:\Documents and Settings\Yese\M y Documents\Visua l Studio 2005\Projects\p roject5\Debug\B uildLog.htm"
1>project5 - 11 error(s), 0 warning(s)



i'm supposed to display the list in the last function...can anyone please help?
Dec 7 '07 #1
2 14904
gpraghuram
1,275 Recognized Expert Top Contributor
HI,
Whenever you define a struuct you shuld use struct keyword while declaring variables of that type or else you shuld do a typedef.

Expand|Select|Wrap|Line Numbers
  1. //your have to change these
  2. void getData(struct studentType sList[], int NO_OF_STUDENTS);
  3. void calculateGrade(struct studentType sList[], int NO_OF_STUDENTS);
  4. void printResult(const struct studnetType sList[], int NO_OF_STUDENTS);
  5.  
  6. //or change the declaraion like
  7. typedef struct _studnetType
  8. {
  9. //
  10. }studnetType ;
  11. //then you can have the code as it is.
  12.  

Raghuram
Dec 7 '07 #2
yalbizu
2 New Member
HI,
Whenever you define a struuct you shuld use struct keyword while declaring variables of that type or else you shuld do a typedef.

Expand|Select|Wrap|Line Numbers
  1. //your have to change these
  2. void getData(struct studentType sList[], int NO_OF_STUDENTS);
  3. void calculateGrade(struct studentType sList[], int NO_OF_STUDENTS);
  4. void printResult(const struct studnetType sList[], int NO_OF_STUDENTS);
  5.  
  6. //or change the declaraion like
  7. typedef struct _studnetType
  8. {
  9. //
  10. }studnetType ;
  11. //then you can have the code as it is.
  12.  

Raghuram


no, it wasn't that at all...i realized i spelled student incorrectly in that function (studnet)...tha t solved all my errors. haha, i feel so dumb. thanks though!
Dec 7 '07 #3

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

Similar topics

6
12546
by: c++newbie | last post by:
Hi all, I try to compile the following classes: main.cpp: #include <algorithm> #include <iostream> #include <fstream> #include <iterator>
3
2215
by: lelle | last post by:
Hi everyone. I discovered a strange phenomena that I'm curios whether anyone else have seen. DB2 V8 fixpak 7a redhat. First some ddl (sorry about the length of this): CREATE TABLE NYA.UPSEC_SUBJECTLEVEL_SUBJECT_UPSEC ( UPSEC_SUBJECT_ID CHAR(5) NOT NULL, GRADE SMALLINT NOT NULL, UPSEC_ID CHAR(9) NOT NULL, UPSEC_SUBJECTLEVEL_ID SMALLINT NOT NULL ) IN USERSPACE1;
7
5017
by: inkexit | last post by:
I'm getting these two error mesages when I try to compile the below source code: error C2065: 'input_file' : undeclared identifier error C2228: left of '.eof' must have class/struct/union type The code below was snipped from a larger program for anyone-who-might-want-to-help-me's convienience. That's why there are varibales declared in the main that are not used in the program, and why the main has such drastic indentation. However,...
7
2485
by: GRoll35 | last post by:
I have 3 files here - Header/Implementation/Driver All it has to do is send the user's input (age)..to the class and the class will figure out the price of the ticket. I'm suppose to create the object and then have it display the cost of the ticket. I'm new to using classes like this so I'm a little confused. Here is the errors I get. If anyone could point out where to start or something that I should keep in mind that would be very...
1
2905
by: uday | last post by:
Hi, I am new to visual c++ and I am trying to compile a Decoder project with library in it. I tried to create a win32 console application and tried to add a compiled static library to it. I ended up with the following error message "Errpr executing c1.exe" as follows. c:\documents and settings\uday\desktop\decode\src\decode\decode_threads.c(504) : error
2
16135
by: cr55 | last post by:
I was wondering if anyone can help me with this programming code as i keep getting errors and am not sure how to fix them. The error code displayed now is error: C2228: left of '.rent' must have class/struct/union type.The problem area is underlined. Any help will be greatly appreciated. #include <c:\cpp\input.h> #include < time.h> #define SIZE 20 struct Cust{ int custno; char fname;
2
2063
by: dblbac | last post by:
i have gone through my c++ program and i keep getting the same error messages: error C2065: 'indata' : undeclared identifier error C2228: left of '.open' must have class/struct/union my program looks like this. if someone could help me fix this problem i will be extremely thankfull #include <iostream> #include <iomanip> #include <string> #include <fstream>
6
2547
by: hsmit.home | last post by:
Hello, I came across a strange error and it's really been bugging me. Maybe someone else has come across this and any insight would be appreciated. What I'm trying to accomplish is using boost::lexical_cast to cast a vector of strings to a string. The compiler I'm using is MSVC++ 2005 Express Edition. The gc++
2
1308
by: Gunners | last post by:
#include<iostream.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> struct st_base { char name; int roll_no; int s1,s2,s3,s4,mks; float percentage;
0
9566
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9393
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,...
0
10153
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9946
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,...
0
9832
tracyyun
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...
0
5272
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...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.