Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,494 members, 7,816,174 topics. Date: Friday, 03 May 2024 at 07:03 AM

C++ Beginner Discussion Room: Drop Your Codes - Programming (5) - Nairaland

Nairaland Forum / Science/Technology / Programming / C++ Beginner Discussion Room: Drop Your Codes (11650 Views)

I Want To Hire A Beginner Who Is Willing To Learn New Skills / Special Codes To Format Text On Nairaland / Should A Beginner Learn 2 Programming Languages At Once? (2) (3) (4)

(1) (2) (3) (4) (5) (Reply) (Go Down)

Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 11:10am On Dec 25, 2013
Kennybix: @ade, can you handle structures? You can use it to 'hold' fractions, and pass it as an argument to functions. It can even be used as a return type!

struct fraction {
int numerator;
int denominator;
};

fraction add(fraction a, fraction b)
{
fraction result;
result.denominator = a.denominator * b.denominator;

result.numerator= (a.numerator * b.denominator) + (b.numerator *a.denominator) ;
return result
}


thanks. I will use class
Re: C++ Beginner Discussion Room: Drop Your Codes by quadrangle: 1:32pm On Dec 27, 2013
here is my code.
//Program: checkbook.cpp
//This program updates a checkbook
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
char trans_type;
double start_bal, trans_amt, end_bal;
//Module for getting data
cout << "Enter your starting balance and press <Enter>" <<endl;
cin >> start_bal;
cout << "Enter your starting balance and press <Enter>" <<endl;
cin >> trans_amt;
cout << "Enter your trans_type 'W' (withdrawal) or 'D' (Deposit) and press <Enter>" <<endl;
cin >> trans_type;

// Perform computation
if(start_bal == 'w')
{
end_bal = start_bal - trans_amt;
}
else
{
end_bal = start_bal + trans_amt;
}
//Print result
cout << "Starting balance is " << start_bal << endl;
cout << "Transaction amount is " << trans_amt << setw(2) << trans_type << endl;
cout << "Ending balance is " << end_bal << endl;
}

1 Like

Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 3:00pm On Dec 27, 2013
quadrangle: here is my code.
//Program: checkbook.cpp
//This program updates a checkbook
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
char trans_type;
double start_bal, trans_amt, end_bal;
//Module for getting data
cout << "Enter your starting balance and press <Enter>" <<endl;
cin >> start_bal;
cout << "Enter your starting balance and press <Enter>" <<endl;
cin >> trans_amt;
cout << "Enter your trans_type 'W' (withdrawal) or 'D' (Deposit) and press <Enter>" <<endl;
cin >> trans_type;

// Perform computation
if(start_bal == 'w')
{
end_bal = start_bal - trans_amt;
}
else
{
end_bal = start_bal + trans_amt;
}
//Print result
cout << "Starting balance is " << start_bal << endl;
cout << "Transaction amount is " << trans_amt << setw(2) << trans_type << endl;
cout << "Ending balance is " << end_bal << endl;
}




nice work
Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 3:01pm On Dec 27, 2013
/* write a program that ask the user to
enter his or her age. then display the
age in months */

#include <iostream>
using namespace std;

void age_in_month(int);

int main()
{

int age;
cout << "Enter your age: ";
cin >> age;

age_in_month(age);


}

void age_in_month(int initial)
{
int month = initial * 12;

cout << initial << " year(s) of age(s) is " << month << " months";

}
Re: C++ Beginner Discussion Room: Drop Your Codes by techwizard(m): 11:18pm On Jan 01, 2014
#include <iostream>
#include <windows.h>
using namespace std;
int main(void){
start:
cout << "Welcome to coded admin login\n" << endl;
cout << "Login using your administrator password:" << endl;
string login;
getline (cin, login);
if (login == "yourPassword"wink{
ShellExecute(NULL, "open", "http://www.highlycoded.com",
NULL, NULL, SW_SHOWNORMAL);
return 0;
}
else
{
cout << "Login failed" << endl;
goto start;
}

cin.get();
return 0;
}

1 Like

Re: C++ Beginner Discussion Room: Drop Your Codes by wisemania(m): 7:52pm On Jan 02, 2014
techwizard: #include <iostream>
#include <windows.h>
using namespace std;
int main(void){
start:
cout << "Welcome to coded admin login\n" << endl;
cout << "Login using your administrator password:" << endl;
string login;
getline (cin, login);
if (login == "yourPassword"wink{
ShellExecute(NULL, "open", "http://www.highlycoded.com",
NULL, NULL, SW_SHOWNORMAL);
return 0;
}
else
{
cout << "Login failed" << endl;
goto start;
}

cin.get();
return 0;
}
Re: C++ Beginner Discussion Room: Drop Your Codes by Nobody: 12:14am On Jan 03, 2014
Was going thru my archive, just tot I drop the codes for a guessing game I wrote as a beginner
Re: C++ Beginner Discussion Room: Drop Your Codes by Nobody: 12:15am On Jan 03, 2014
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
int usernum, compnum, playagain;
void gamestart(){
int quit, level;
cout << endl;
cout << " GUESSING GAME!!! " << endl<<endl;
cout << " to continue press 1 " << endl;
cout << " to end the game press 2 " << endl;
cin >> quit ;
if (quit == 2){
cout << " gooood byee " ;
}

if (quit == 1){
cout << endl;
cout << " enter any difficulty level btw 1 and 1000" << endl;
cin >> level;
cout << endl;
cout << " hmmm... level " << level << " selected , let the game begin!! " <<endl<<endl;
cout << " computer is thinking of a number btw 1 and " << level << endl;
cout <<" try and guess what number it is " << endl;
cin >> usernum;
compnum = rand()% level;
}

}
void game (int usernum, int compnum){
while (usernum!=compnum){
if (usernum < compnum ){
cout << " your guess is to low , please try again " << endl<< endl;
cout << ">> ";
cin >> usernum;
}
if ( usernum > compnum ) {
cout << " your guess is to high , try again " << endl<< endl;
cout << ">> ";
cin >> usernum;
}
}
if (usernum == compnum){
cout << " congrats , you win!!! " << endl;
cout << " press 1 to play again " << endl;
cout << " press 2 to quit " << endl;
cin >> playagain ;
}
if(playagain == 1){
gamestart();
game (usernum, compnum);
} else { cout << " gooood byee " ;
}

}
int main (){
srand(time(NULL));
gamestart();
game (usernum, compnum);
}
Re: C++ Beginner Discussion Room: Drop Your Codes by Borwe: 2:55pm On Jan 03, 2014
adelolaa: screenshots

how did you do that exactly? What app is it ? And what's the procedure ?
Re: C++ Beginner Discussion Room: Drop Your Codes by Olyboy16(m): 12:20am On Jul 27, 2014
raynold: I kinda(not like a pro) knw c, c++ and java
I dislike arrays and pointers
just like saying u ar a footballer but you dont like scoring!
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 12:15pm On Jul 27, 2014
Olyboy16:
just like saying u ar a footballer but you dont like scoring!
lol... am improving every day even with the very little time I have to practice..

1 Like

Re: C++ Beginner Discussion Room: Drop Your Codes by losprince(m): 7:06pm On Jul 27, 2014
iamDemigod: #include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
int usernum, compnum, playagain;
void gamestart(){
int quit, level;
cout << endl;
cout << " GUESSING GAME!!! " << endl<<endl;
cout << " to continue press 1 " << endl;
cout << " to end the game press 2 " << endl;
cin >> quit ;
if (quit == 2){
cout << " gooood byee " ;
}

if (quit == 1){
cout << endl;
cout << " enter any difficulty level btw 1 and 1000" << endl;
cin >> level;
cout << endl;
cout << " hmmm... level " << level << " selected , let the game begin!! " <<endl<<endl;
cout << " computer is thinking of a number btw 1 and " << level << endl;
cout <<" try and guess what number it is " << endl;
cin >> usernum;
compnum = rand()% level;
}

}
void game (int usernum, int compnum){
while (usernum!=compnum){
if (usernum < compnum ){
cout << " your guess is to low , please try again " << endl<< endl;
cout << ">> ";
cin >> usernum;
}
if ( usernum > compnum ) {
cout << " your guess is to high , try again " << endl<< endl;
cout << ">> ";
cin >> usernum;
}
}
if (usernum == compnum){
cout << " congrats , you win!!! " << endl;
cout << " press 1 to play again " << endl;
cout << " press 2 to quit " << endl;
cin >> playagain ;
}
if(playagain == 1){
gamestart();
game (usernum, compnum);
} else { cout << " gooood byee " ;
}

}
int main (){
srand(time(NULL));
gamestart();
game (usernum, compnum);
}

quite creative
Re: C++ Beginner Discussion Room: Drop Your Codes by Artorius(m): 1:22am On Sep 17, 2014
Hello guys, well the thread is in hibernation; sorry to disturb grin I'm learning c++, and I'm wondering how I can execute c++ codes on my android device. Yea I saw one or two posts on the thread about using c4droid, after installing I was directed to also install gcc and sdl which I also did. But it's as if the gcc app isn't integrated into the c++ or something like that. Even when I try to fix that in the c4droid preferences, I'm still directed to install the gcc plugin which I have already! Can somebody please give me tips on how to fix this? I'll be most grateful, and I'll sure be coming back to ask more questions, thanks.
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 8:31am On Sep 18, 2014
Artorius: Hello guys, well the thread is in hibernation; sorry to disturb grin I'm learning c++, and I'm wondering how I can execute c++ codes on my android device. Yea I saw one or two posts on the thread about using c4droid, after installing I was directed to also install gcc and sdl which I also did. But it's as if the gcc app isn't integrated into the c++ or something like that. Even when I try to fix that in the c4droid preferences, I'm still directed to install the gcc plugin which I have already! Can somebody please give me tips on how to fix this? I'll be most grateful, and I'll sure be coming back to ask more questions, thanks.
download the c4droid from the playstore(payed tho)..
Re: C++ Beginner Discussion Room: Drop Your Codes by Borwe: 2:46pm On Sep 20, 2014
raynold: download the c4droid from the playstore(payed tho)..

There us CCTools-free. It's free. Only thing is it downloads packages on first run. about 50mb.
Re: C++ Beginner Discussion Room: Drop Your Codes by AptechWorld: 8:13pm On Sep 21, 2014
Friends,

Information and Communication Technology (I.C.T) is ushering in a new Economic
Order. It has become a necessity and the earlier you position yourself
by gathering the needed skills-set the better.

The days when some selected disciplines were considered the
gold standard are done for good. No matter your profession, harnessing the gains
of Information Technology Infrastructure for organizational
profitability is the relevant subject in boardrooms across the globe.

You must have heard of the new guys at the Board Room...The C.T.O(Chief Technology Officers)! Soon they will be chairing the Board because they are increasingly becoming indispensable.

Aptech is training and raising a generation of I.T professionals that will set the pace and engineer the future.




Ben

Work: +234 817 212 2383
Mobile: +234 803 796 6539
Website: www.stplglobal.com
Address: 57A, Adeola Odeku Street, Victoria Island, Lagos, Nigeria
“It is by meeting the Noble standards you have set for yourself that self is enhanced”
Re: C++ Beginner Discussion Room: Drop Your Codes by Nobody: 3:39pm On Sep 22, 2014
adelolaa: /********************************

Assignments: (if, else if and else statement)

HOD: ALEX ALLAIN

STUDENT: XARMZON

COURSE: JUMPING INTO C++

Q1: Ask the user for two user's ages, and indicate who is older, behave differently if both are over 100.

Q2: Implement a simple "password" system that takes a password in the form of a number. Make it so that either of the two numbers are valid, but use only one if statement to do the check.

Q3: Write a small calculator that takes as input one of the four arithmetic operations, the two argument to those operation, and then print out the result.

Q4: Expand the password checking program from earlier in this chapter and make it multiple usernames. Each with their own password and provide the ability to prompt user's again if the first attempt failed. Think about how easy(or hard) it is to do this for a lot of usernames and password.


SOLUTION TO Q1:

********************************/

#include <iostream>

#include <string>

using namespace std;


int main()
{
int firstAge;
int secondAge;

cout << "Enter the first and second person age " << endl;
cin >> firstAge >> secondAge;

if (((firstAge && secondAge) < 100) && ((firstAge && secondAge) >= 1))

{

if (firstAge > secondAge)
{
cout << " First person is older than second person" << endl;
}
if (firstAge < secondAge)
{
cout << "Second Person is older than first person" << endl;
}

}

if (firstAge && secondAge >= 100)
{
cout << "Both ages is 100 or greater than 100" << endl;
}
else
{
cout << "Invalid Ages" << endl;
}



}

if they are off the same age
Re: C++ Beginner Discussion Room: Drop Your Codes by Sirnuel: 3:03pm On Sep 28, 2014
wisemania:

http://mirror7.meh.or.id/Magazines/hakin9/Packtpub.Metasploit.Penetration.Testing.Cookbook.Jun.2012.pdf

http://adrem.ua.ac.be/sites/adrem.ua.ac.be/files/sqlinjbook.pdf

http://library.back2hack.cc/books/Hacking/Syngress_-_XSS_Attacks_[]_(2007)_en.pdf

http://mirror7.meh.or.id/ebooks/11_TheWeb%20Application%20Hackers%20Handbook.pdf

dizzzz books r basically about web hacks and security.....i hope it wont prevent u 4rm fulfillin ur Android/iOS dev ..... Stil av mor...bt download dizzzz first....i av on objective-c aswell.....objective-c codes r lovely and lighter dan java u kw.... grin


Pls can u e-mail links to those your e-books??

Especially the ones on c and hacking

<a href="www.sirnuell@gmail.com"<MY Email</a>
Re: C++ Beginner Discussion Room: Drop Your Codes by olaoreAd: 9:27am On Oct 03, 2014
I'm happy to see my fellow c++ visionaries here, and I have created a group on whatsapp where we can talk on better and improved project on c++. To join the group simply comment with ur phone number or add me with 07036792585 and ur first message should me c++ visionary. Together we can make Nigeria proud.

(1) (2) (3) (4) (5) (Reply)

Letter From The Moderator - Please Read / How To Convert Folder/file To Jpeg Format / Computer Science/programming Challenging Questions

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 63
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.