OMG i got an 80 out of 100 on this?

Discussion in 'OT Technology' started by Chimpa Codigo, Nov 15, 2002.

  1. Chimpa Codigo

    Chimpa Codigo Bаnned bу Ѕuреr Modulators

    Joined:
    Jan 27, 2001
    Messages:
    68,463
    Likes Received:
    21
    Location:
    Salinas, CA
    someone must seriously like me :confused: sent out the wrong version of my midterm. It didn't work at all and i got an 80?????? :wtf: is wrong with this world

    Code:
    //Midterm Question 1
    
    #include <iostream>
    #include <fstream.h>
    
    struct customer
    {
    	int accountNum;
    	float balance;
    	int numCheck;
    	float *checks;
    	float checkTotal;
    	float checkdeposit;
    	float overdrawn;
    };
    
    void makeData(customer & data, ofstream & out)
    {
    	cin >> data.accountNum;
    	out << data.accountNum << endl;
    
    	cin >> data.balance;
    	out << data.balance << endl;
    
    	cin >> data.numCheck;
    	out << data.numCheck << endl;
    
    	data.checks = new float[data.numCheck];
    	data.checkTotal = 0;
    	for(int i = 0; i < data.numCheck; i++)
    	{
    		cin >> data.checks[i];
    		out << data.checks[i] << endl;
    		data.checkTotal +=data.checks[i];
    	}
    	cin >> data.checkdeposit;
    	out << data.checkdeposit << endl;
    	out << data.checkTotal << endl;
    	data.overdrawn = data.balance - data.checkTotal + data.checkdeposit;
    	out << data.overdrawn << " ";
    }
    
    void getData(customer & data, ifstream& in)
    {
    	in >> data.accountNum;
    
    	in >> data.balance;
    
    	in >> data.numCheck;
    
    	data.checks = new float[data.numCheck];
    	for(int i = 0; i < data.numCheck; i++)
    	{
    		in >> data.checks[i];
    	}
    	in >> data.checkdeposit;
    	in >> data.checkTotal;
    	in >> data.overdrawn;
    }
    
    void displayData(customer & data)
    {
    	cout<< endl << "Account number: " << data.accountNum <<endl
    		<< "Balance to date: "<< data.balance <<endl
    		<< "Number of checks written this month: " << data.numCheck << endl
    		<< "Total amount of written checks: " << data.checkTotal << endl
    		<< "Total amount deposited this month: " << data.checkdeposit <<endl
    		<< "New balance: "<< data.overdrawn << endl;
    	data.balance = data.overdrawn;
    	if(data.balance < 0)
    	{
    		data.balance -= 20;
    		cout << "The account has been over drawn and will be accessed a $20 fee" << endl;
    	}
    }
    
    
    void bank(void)
    {
    	customer *data = new customer;
    	ifstream in("accounts.bin", ios::binary);
    	ofstream out("accounts.bin", ios::binary);
    	int c = 0;
    	/*for(int i = 0; i < 3; i++)
    	{
    		makeData(data[i]);
    	}*/
    	out.close();
    	int i = 0;
    	while(!in.eof())
    	{
    		getData(data[i], in);
    		i++;
    		c++;
    	}
    	i = 0;
    	for(; i < c; i++)
    	{
    		displayData(data[i]);
    	}
    	in.close();
    	delete data;
    }
    
    //Midterm Question 2
    
    float grossPay(float,float,int);
    
    struct employees
    {
    	int empNum;
    	int hours;
    	float rate;
    	float gross;
    };
    
    void getInfo(employees & data, ifstream & in)
    {
    	in >> data.empNum;
    	in >> data.hours;
    	in >> data.rate;
    	grossPay(data.rate, data.gross, data.hours);
    }
    
    void outputInfo(employees & data, ofstream & out)
    {
    	out << data.empNum << " ";
    	out << data.hours << " ";
    	out << data.rate << " ";
    	out << data.gross << endl;
    }
    float grossPay(float a, float b, int c)
    {
    	if(c > 40)
    	{
    		b = 40*a;
    		int timeHalf = c - 40;
    		b += timeHalf*(a+(a/2));
    		if(c > 50)
    		{
    			int dubTime = timeHalf - 10;
    			b += dubTime*(2*a);
    		}
    		return b;
    	}
    	b = a*c;
    	return b;
    }
    
    void grossEmployees(void)
    {
    	employees *data = new employees;
    	ifstream in("employees.bin", ios::binary);
    	ofstream out("employees.ran", ios::binary);
    	fstream random("employees.ran", ios::in, ios::out);
    	int i = 0;
    	while(!in.eof())
    	{
    		do
    		{
    			getInfo(data[i], in);
    			outputInfo(data[i], out);
    			i++;
    		}while(data[i].empNum>1 || data[i].empNum<3);
    		out.close();
    		in.close();
    		break;
    	}
    	cout << "Which Employee would you like to lookup? ";
    	cin >> i;
    	while(random.seekg(data[i].empNum))
    	{
    		cout << data[i].empNum;
    	}
    }
    
    //Midterm Question 3
    
    void numberCrunch(int *);
    void encrypt(int *);
    void swap(int &, int &);
    
    void encryptFile(ofstream & binary, int *a)
    {
    	encrypt(a);
    	swap(*(a+0), *(a+2));
    	swap(*(a+1), *(a+3));
    	for(int i = 0; i < 6; i++)
    	{
    		cout << *(a+i);
    		binary << *(a+i) << endl;
    	}
    	cout << endl;
    }
    
    void decryptFile(ifstream & in, int *a)
    {
    	int i = 0;
    	while(!in.eof())
    	{
    		in >> *(a+i);
    		i++;
    	}
    	
    	swap(*(a+0), *(a+2));
    	swap(*(a+1), *(a+3));
    	i = 0;
    	for(;i < 6; i++)
    	{
    		*(a+i) =(*(a+i)+5)%8;
    		cout << *(a+i);
    	}
    }
    
    
    void telephone(void)
    {
    	int *data = new int;
    	numberCrunch(data);
    	ofstream binary("encryption.bin", ios::binary);
    	encryptFile(binary, data);
    	binary.close();
    	ifstream in("encryption.bin", ios::binary);
    	decryptFile(in, data);
    }
    
    
    void encrypt(int *a)
    {
    	
    	for(int i = 0; i < 6; i++)
    	{
    		*(a+i) =(*(a+i)+5)%8;
    	}
    }
    
    void numberCrunch(int *a)
    {
    	for(int i = 0; i < 6; i++)
    	{
    		cin >> *(a+i);
    		while(*(a+i) > 7||*(a+i) < 0)
    		{
    			cout << "Please insert a number between 0 and 7";
    			cin >> *(a+i);
    		}
    	}
    }
    
    void swap(int &a, int &b)
    {
    	a=a^b;
    	b=a^b;
    	a=a^b;
    }
    
    //Midterm Question 5
    
    void conversions (void)
    {
    	cout << " The binary equivalent to the decimal number 19 is 00010011" << endl;
    	cout << " The hexadecimal equivalent to the decimal number 19 is 13" << endl;
    	cout << " The binary equivalent to the hexadecimal number FB is 11111101" << endl;
    	cout << " The decimal equivalent to the hexadecimal number FB is 251" << endl;
    }
    
    main()
    {
    	int option;
    	option = 10;
    	while (option > 0)
    	{
    		cout << "\n" << "Enter zero to quit this program or choose from the programs below" 
    			<< "\n" << "\t" << "1. Question 1 " << "\n" << "\t" << "2. Question 2" << "\n"
    			<< "\t" << "3. Question 3" << "\n" << "\t" << "4. Question 5";
    		cin >> option;
    		while (option > 4)
    		{
    			cout << "\n" << "you chose a number not listed please chose a different number"
    			<< "\n" << "\n" << "Enter zero to quit this program or choose from the programs below" 
    			<< "\n" << "\t" << "1. Question 1 " << "\n" << "\t" << "2. Question 2" << "\n"
    			<< "\t" << "3. Question 3" << "\n" << "\t" << "4. Question 5" << endl;
    			cin >> option;
    		}
    		if (option == 0)
    		{
    			return 0;
    		}
    		if (option == 1)
    		{
    			bank();
    		}
    		if (option == 2)
    		{
    			grossEmployees();
    		}
    		if (option == 3)
    		{
    			telephone();
    		}
    		if (option = 4)
    		{
    			conversions();
    		}
    	}
    
    	return 0;
    }
    
    I was trying to figure out why the hell he was looking at me funny, then went to my assembly class and found my disk and now I know why.....i guess I'd be perfect for microsoft :)

    kinda sucks though because i could have easily gotten 100 :(
     
  2. accordfreak93

    accordfreak93 Go Preds!

    Joined:
    Apr 7, 2002
    Messages:
    4,511
    Likes Received:
    0
    Location:
    TN
    shit man, im only in my second year in c++(highschool). that code makes my work look like somethin a kid could do. anyways, lucky you.
     
  3. Sakino

    Sakino I Live In A Giant Bucket

    Joined:
    Mar 14, 2002
    Messages:
    2,535
    Likes Received:
    0
    That is basic C++, I been learning other shit that seems a lot more complicated then that in my second class of C++ for college. It sucks :)
     
  4. accordfreak93

    accordfreak93 Go Preds!

    Joined:
    Apr 7, 2002
    Messages:
    4,511
    Likes Received:
    0
    Location:
    TN
    damn, i got a long way to go then.
     
  5. turbo91

    turbo91 New Member

    Joined:
    Jun 14, 2002
    Messages:
    2,521
    Likes Received:
    0
    Location:
    San Diego, CA
    That must be a pathetic C++ class if that is your midterm.

    There is almost no C++ in that program at all. I see reference passing and streams. Wow.

    You aren't even using classes.
     
  6. Chimpa Codigo

    Chimpa Codigo Bаnned bу Ѕuреr Modulators

    Joined:
    Jan 27, 2001
    Messages:
    68,463
    Likes Received:
    21
    Location:
    Salinas, CA
    we're dealing with classes at the end (right now). If i used classes instead of structures (which are the same damn thing as classes) i would have ended up getting an F (teachers responds :dunno:) somehow i pulled of an 80 off of a non working program that could have easily been made with object oriented programming methods, but would have taken alot longer to do.
     
  7. BaZ

    BaZ 2004 ACC Champions

    Joined:
    Jun 12, 2001
    Messages:
    2,005
    Likes Received:
    0
    Location:
    Hokieville, USA
    :eek: classes are NOT the same thing as structs
     
  8. turbo91

    turbo91 New Member

    Joined:
    Jun 14, 2002
    Messages:
    2,521
    Likes Received:
    0
    Location:
    San Diego, CA

    next post: "I can't believe I got a 5 out of 100 on my C++ final"
     
  9. Chimpa Codigo

    Chimpa Codigo Bаnned bу Ѕuреr Modulators

    Joined:
    Jan 27, 2001
    Messages:
    68,463
    Likes Received:
    21
    Location:
    Salinas, CA
    If i were to use them on my midterm they would have been used exactly the same way as the structures.
     
  10. UncleGene

    UncleGene And when I say brother, I don't mean, like, an act

    Joined:
    Nov 17, 2001
    Messages:
    2,083
    Likes Received:
    0
    im a first year college student learning c++ and that is WOW :o
     
  11. turbo91

    turbo91 New Member

    Joined:
    Jun 14, 2002
    Messages:
    2,521
    Likes Received:
    0
    Location:
    San Diego, CA
    This worries me about the future of "programmers".

    I don't understand how a college student would never have been exposed to C++ before college...are you a comp sci/eng major?
     
  12. Chimpa Codigo

    Chimpa Codigo Bаnned bу Ѕuреr Modulators

    Joined:
    Jan 27, 2001
    Messages:
    68,463
    Likes Received:
    21
    Location:
    Salinas, CA
    you were absolutly correct, good thing i figured that out before taking the final :)
     
  13. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Obviously not everyone has as much programming experience as you did going into college. I'm in grade 11, and I do have a fair bit of C++ experience, but I know lots of people who don't but are planning to go into comp sci/eng like I am. As long as they learn and catch on quickly, I'd say they'll probably be fine (from what I hear of the comp sci curriculum here from realiable sources).

    However, if the end of that C++ course is classes, I must say it sounds mighty similar to our programming 30 course...
     
  14. Kabuko

    Kabuko Guest

    Plenty of college students have no experience in C++ prior to college. It's actually rather common, the norm rather than the strange thing you make it out to be. In fact that's what introductory programming classes are for--teaching you programming. Most programs don't assume prior knowledge.
     
  15. BaZ

    BaZ 2004 ACC Champions

    Joined:
    Jun 12, 2001
    Messages:
    2,005
    Likes Received:
    0
    Location:
    Hokieville, USA
    i learned most of the c++ tricks of the trade in a 2 week crash course my senior year in high school (2 years ago) through and internship: polymorphism, pointers, operator, overloads, inheritance but i totally missed out on learning the advanced data structures (binary trees, linked lists, etc). good thing data structures are easy to pick up on
     

Share This Page