0% found this document useful (0 votes)
5 views

structs with pointers

Uploaded by

bahiyahoosen6
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

structs with pointers

Uploaded by

bahiyahoosen6
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <fstream>
using namespace std;

struct STUDENT
{
string NAME;
int STUDENTNUMBER;
double GPA;

};

void studentdata (STUDENT * freshman) //basically you made freshman a variable of


the structure
// that can actually hold information in by
using *
{

//get the student name

cout << "Enter the students name :";


cin >> (freshman -> NAME );
// now you accessed the freshamn variables and directly stored it under certain
"headings" instead
// of just having freshaman and a bunch of random varibles stored in it
cout << endl;

//get student number and store it in the STUDENTNUMBER variable

cout << "Enter the students number :";


cin >> (freshman -> STUDENTNUMBER );
cout << endl;

// get students gpa and store it in the gpa variable

cout << "Enter the students GPA :";


cin >> (freshman -> GPA );
cout << endl;

int main ()
{

STUDENT freshman;

cout << "Enter the following student information : " << endl;
studentdata(&freshman);
// now that you have stored frehsman in the computer ,the computer lost it and
now you have to find
// it by finding its address which uses the &
cout <<"Here is the information you entered :" << endl;
cout << "NAME :" << freshman.NAME << endl;
cout << "STUDENT NUMBER :" << freshman.STUDENTNUMBER << endl;
cout << "STUDENT GPA :" << freshman.GPA << endl;

return 0;

#include <iostream>
#include <string>
using namespace std;
struct Two {int two;};
class Four
{
int one, two;
public:
Four(){};
~Four(){};
four(int w){};
Four(string w){};
getOne(int one){
return one;
};
};
class three{
private:
int one;
int two;
Four four;
public:
three(){};
int getOne(four v){
return v.one ;
};
void setTwo(Two tw){
Four.two = 2;
};
three(){
delete four;
};
};
int main () {
Four f;
three t;
t->getOne(f);
return 0;
}

You might also like