U E D R , A S I H C RSS

Cpp Study_2002_1/과제1/Cherry Boy


~cpp 

====================================================================

// 1  ...


#include <iostream>
using namespace std;
void print(char *,int n=0);

int main()
{
	char exam[40];
	int choice;
	do
	{
		cout << "(20) ...\n";
		cin.getline(exam,40);
		cout << " .. _\b";
		cin >> choice;
		cin.get();
		print(exam,choice);
	}while(choice==0);
	return 0;
}

void print(char *exam,int n)
{
	static int count=0;
	if(n==0)
		cout << exam << endl;
	else
	{
		cout << "  " << count << "  .\n";
		for(int i=0;i<count;i++)
			cout << exam << endl;
	}
	count++;
}

/*
0     ... 
0   ..
*/

========================================================================

// 2  ...


#include <iostream>
using namespace std;
struct candybar
{
	char name[30];
	double weight;
	int cal;
}candy;

void print(candybar &, char * name="millenium Munch",double weight=2.85,int cal=350);

int main()
{
	print(candy);
	return 0;
}

void print(candybar &candy,char * name,double weight,int cal)
{
	for(int i=0;i<30;i++)
		candy.name[i]=name[i];
	candy.weight=weight;
	candy.cal=cal;
	cout << " \t:\t" << candy.name <<endl;
	cout << " \t:\t" << candy.weight << endl;
	cout << " \t:\t" << candy.cal << endl;
}

===================================================================


// 3 ..


#include <iostream>
using namespace std;
#include <cstring>
struct stringy
{
	char * str;
	int ct;
};

void show(char *, int n=1);
void show(stringy, int n=1);
void set(stringy &,char *);

int main()
{
	stringy beany;
	char testing[] = "Reality isn't what it used to be.";

	set(beany,testing);
	show(beany);
	show(beany,2);
	testing[0]='D';
	testing[1]='u';
	show(testing);
	show(testing,3);
	show("Done!");
	return 0;
}

void show(char *string,int n)
{
	for(int i=0;i<n;i++)
		cout << string << endl;
}

void show(stringy beany,int n)
{
	for(int i=0;i<n;i++)
		cout << beany.str << endl;
}

void set(stringy &beany,char *string)
{
	char* temp=new char[strlen(string)];
	temp=string;
	beany.str=temp;	
	beany.ct=strlen(beany.str);
}

=============================================================

//4..

// .

// golf.h  --  pe8-3.cpp  해

#include <iostream>
#include <cstring>
using namespace std;

const int Len=40;
struct golf
{
	char fullname[Len];
	int handicap;
}g1,g2;

//함   
//  1 ,    0 

int setgolf(golf & g);

//함    
//golf    

void setgolf(golf & g, const char * name, int hc);

//함 handicap  화한.

void handicap(golf & g, int hc);

//함 golf  

void showgolf(const golf & g);

int main()
{
	int k;
	do
	{
		k=setgolf(g1);
		setgolf(g2, "DKNY", 100);
		handicap(g2,77);
		showgolf(g1);
		cout<<endl;
		showgolf(g2);
	}while(k!=0);
	return 0;
}

int setgolf(golf & g)
{
	cout << "What's U'r name?\n";
	cin >> g.fullname;
	cout << "Handicap?\n";
	cin >> g.handicap;
	if(g.fullname==NULL)
		return 0;
	else
		return 1;
}

void setgolf(golf & g, const char * name, int hc)
{
	strcpy(g.fullname,name);
	g.handicap=hc;
}

void handicap(golf & g, int hc)
{
	g.handicap=hc;
}

void showgolf(const golf & g)
{
	cout << "Name    \t:\t" << g.fullname << endl;
	cout << "HandyCap\t:\t" << g.handicap << endl;
}


=============================================================



Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:01
Processing time 0.0118 sec