Categories
Uncategorised

Structures – Returning Reference to a Structure

/* Copyright (C) 2007 Ankur Banerjee. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html /

/ Function returning reference to a structure – WAP to add distances
entered in feet and inches /

#include <iostream.h>
#include <conio.h>

struct dist
{
int feet, inches;
} result;

void main()
{
clrscr();
dist d1, d2;
dist& add (dist&, dist&);
cout<<“Enter first distance : “;
cin>>d1.feet>>d1.inches;
cout<<“Enter the second distance : “;
cin>>d2.feet>>d2.inches;
result = add(d1, d2);
cout<<“Added result is “<<result.feet<<” feet ” <<result.inches<<” inches”<<endl;
getch();
}

dist& add (dist &a1, dist &a2)
{
dist res;
res.feet = (a1.feet + a2.feet) + ((a1.inches + a2.inches)/12);
res.inches = (a1.inches + a2.inches)%12;
return res;
}

/ Output */

Enter first distance :6
5
Enter
the second distance :8
2
Added result is 14 feet 7 inches

Categories
Personal Reflections

C++ Programs on GQB

I’ve come up with a new idea for GQB. I’m going to put up the code for EACH and EVERY C++ program they give at school. Yes folks, so that everyone can come, copy-paste it, and get away with a free lunch. It goes like this – since I’ve to do the work anyway, I’ll do it, and then put it here. By the Universal Laws of Laziness, I expect a significant amount of the 160+ students in the computer science sections of DPS Vasant Kunj to come here to save themselves trouble. I get more viewers, and maybe will retain some readers. Please do note that I’m NOT sending these via the mailing list, you’ll have to come here to get it.

Update: Since I have to edit the HTML code to display the characters here, please do inform me if there are any errors while displaying on my blog, or whether there are any errors in the code. Stupid Blogger, they sometimes irk me when they implement their own flawed logic on inserted HTML code, and try to display it their way. Ditto for WordPress. I could’ve gotten away at many places with the CODE tag, but these to moronic services don’t allow me to.