Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1

    Default C++ Data Structure assignment...


    hi...

    ok lang ba mag post ug asynment diri??sa foreign forums man gud kay paka-ulawan ka kung magpost ka ug asynment labina na kung wala kay codes nga mapakita...sa tinuod lang wala jud ko'y codes nga mapakita ani amung asynment...pait pud kau ang strategy samung maestro oi kay reporting...unya utro pud ming mga reporters mag lisud sa amung mga topics, mao na dli na hinuon matarung ug explain ang mga assigned topics samu...mao na ugsahay maka-discourage jud ang ka-lisud...

    nweiz mao diay ni amung asynment...

    Code:
    Each unit in a Latin textbooks contains a latin English vocabulary of words that have been
    used for the first time in a particular unit. Write a program that converts a such of vocabularies
    stored file latin into a set of English- Latin vocabularies. Make the following assumptions:
    
    a. Unit names are preceded by a percentage symbol.
    b. There is only one entry per line.
    c. A latin word is separated by a colon from its english equivalent(s), 
    if there is more than one equivalent(s), they are separated by a comma.
    
    To output a English word in alphabetical order, create a binary search tree for each 
    unit containing english words and linked list of Latin equivalents. Make sure that there is only
    one node for each English word in tree. For example there is only one node for and, although and is used
    twiced in unit 6: with words ac and atque. After the task has been completed for a given unit(that is a content 
    of the tree has been stored in an output file), delete the tree along with all linked lists from computer memory 
    before creating a tree for the next unit. 
    
    (Here is an example of a file containing Latin-English vocabularies:)
    
    % Unit 5
    ante: before, in front of, previously
    antiquus: ancient
    ardeo: burn, be in fire, desire
    arma: arms, weapons
    aurum: gold
    aureus: golden, of gold
    
    % Unit 6
    animal: animal
    Athenae: Athens
    atque: and
    ac: and
    aurora: dawn
    
    % Unit 7
    amo: love
    amor: love
    annus: year
    Asia: Asia
    
    From these units, the program should generate the following output:
    
    % Unit 5
    ancient: antiquus
    arms: arma
    be on fire: ardeo
    before: ante
    burn: ardeo
    desire: ardeo
    gold: aurum
    golden: aureus
    in front of: ante
    of gold: aureus
    previously: ante
    weapons: arma
    
    % Unit 6
    Athens: Athenae
    and: ac,atque
    animal: animal
    dawn: aurora
    
    % Unit 7
    Asia:Asia
    love: amor, amo
    year: annus

  2. #2
    unsa nga c++ inyong gigamit?

  3. #3
    unsa pasabot nimu darkhero??

    unsa na book ba imung pasabot??

    wala man mi librohay...pero ang gamit samung maestro nga book kay Data Structures and Algorithms in C++ by Adam Drozdek 2nd edition...

    or ang C++ compiler imung pasabot??

    ang gamit namo kay Dev C++ ugsahay Turbo C++, depende sa amung maestro...

    ugsahay pud maabot ra mi kalit ug Java, depende sa example...



  4. #4
    ako ra gi-sure kung unsa nga c++ inyong gigamit, standard ba or dili. so ok ra kung dev c++ gamiton?

    by the way, mingw ang compiler sa dev-c++, port na sa gcc, which is preferable pud gamiton kay compliant man sa standardized c++ unlike sa turbo c++ nga na-relic na intawn

  5. #5
    sa tinuod lang...Turbo C++ jud ang pinaka una nga gi introduce samoh katong programming 1 pa, unya mao na among na andan...ambot nganu, nga karaan nmn unta ang turbo c++...mao na naghinay-hinay ko ug tuon pag-gamit anang Dev C++...

  6. #6
    cge bro, tulog sa ko. kung di gani ko ma-busy unya inig mata, basin makatabang ko ani nga problema. asa man imong mas prefer gamiton, dev c++ or turbo c++? lisod na gamitan ug stl unya di modagan kay ang gigamit relic na nga compiler

  7. #7
    payts na Dev C++...maulaw man pud tah ani oie...ga samuk-samuk jud ko ug taman bah...whew!!
    cge bro salamat sa pag entertain saq kadali...

  8. #8
    nah, ug tabangan ni nimo buhat di jd ni makat-on ang TS..

  9. #9
    grabeh pud nang di makat-un oi...

    la lang jud naq kaau na absorb ug pag-ayo ang tibuok data struct...naa man ju'y tao nga slow learner pareha naq...naa pa'y maestro nga mura rag minor iyang gitudlo...nag salig kay ni graduate na(fresh graduate)...

    wala man pud q namugos...ma-ulaw tah...hehehe...

  10. #10
    file: latin.cpp
    Code:
    #include <string>
    #include <fstream>
    #include <iostream>
    
    
    #define LATIN_FILE "latin.txt"
    #define ENGLISH_FILE "english.txt"
    
    
    using namespace std;
    
    
    struct tree
    {
    	string english;
    	string latin;
    	tree *left;
    	tree *right;
    
    	tree(string eng = "", string lat = "")
    	{
    		english = eng;
    		latin = lat;
    		left = NULL;
    		right = NULL;
    	}
    };
    
    
    bool exists(tree *root, string english, string latin)
    {
    	if (root == NULL)
    	{
    		return false;
    	}
    	else if (english == root->english)
    	{
    		root->latin = latin + ", " + root->latin;
    
    		return true;
    	}
    	else if (english < root->english)
    	{
    		return exists(root->left, english, latin);
    	}
    	else
    	{
    		return exists(root->right, english, latin);
    	}
    }
    
    
    void insert(tree *&root, string english, string latin)
    {
    	if (root == NULL)
    	{
    		root = new tree(english, latin);
    	}
    	else
    	{
    		if (!exists(root, english, latin))
    		{
    			if (english < root->english)
    			{
    				insert(root->left, english, latin);
    			}
    			else
    			{
    				insert(root->right, english, latin);
    			}
    		}
    	}
    }
    
    
    void print(tree *root, ofstream &output)
    {
    	if (root != NULL)
    	{
    		print(root->left, output);
    		output << root->english << ": " << root->latin << endl;
    		print(root->right, output);
    	}
    }
    
    
    void reset(tree *&root)
    {
    	if (root->left != NULL)
    	{
    		reset(root->left);
    	}
    
    	if (root->right != NULL)
    	{
    		reset(root->right);
    	}
    
    	delete root;
    	root = NULL;
    }
    
    
    string trim(const string &line)
    {
    	size_t start = line.find_first_not_of(" \t\r\n");
    
    	if (start != string::npos)
    	{
    		return line.substr(start, line.find_last_not_of(" \t\r\n") - start + 1);
    	}
    
    	return "";
    }
    
    
    int main(void)
    {
    	tree *root;
    	string unit;
    	string line;
    	bool start = false;
    
    	root = NULL;
    
    	remove(ENGLISH_FILE);
    
    	ifstream input(LATIN_FILE);
    	ofstream output(ENGLISH_FILE);
    
    	while (getline(input, line))
    	{
    		line = trim(line);
    
    		if (!line.empty())
    		{
    			if (line.substr(0, 1) == "%")
    			{
    				if (root != NULL)
    				{
    					if (!start)
    					{
    						start = true;
    					}
    					else
    					{
    						output << endl;
    					}
    
    					output << unit << endl;
    					print(root, output);
    					reset(root);
    					unit = "";
    				}
    
    				unit = line;
    			}
    			else
    			{
    				string word;
    				string latin;
    				string english;
    
    				for (size_t index = 0; index < line.length(); index++)
    				{
    					string character = line.substr(index, 1);
    
    					if (character == ":")
    					{
    						word = trim(word);
    
    						if (!word.empty())
    						{
    							latin = trim(word);
    							word = "";
    						}
    					}
    					else if (character == ",")
    					{
    						if (!latin.empty())
    						{
    							english = trim(word);
    
    							if (!english.empty())
    							{
    								insert(root, english, latin);
    								word = "";
    							}
    						}
    					}
    					else
    					{
    						word += character;
    					}
    				}
    
    				if (!latin.empty())
    				{
    					english = trim(word);
    
    					if (!english.empty())
    					{
    						insert(root, english, latin);
    					}
    				}
    			}
    		}
    	}
    
    	if (root != NULL)
    	{
    		if (start)
    		{
    			output << endl;
    		}
    
    		output << unit << endl;
    		print(root, output);
    		reset(root);
    	}
    
    	output.close();
    	input.close();
    
    	return 0;
    }
    file: latin.txt
    Code:
    % Unit 5
    ante: before, in front of, previously
    antiquus: ancient
    ardeo: burn, be in fire, desire
    arma: arms, weapons
    aurum: gold
    aureus: golden, of gold
    
    % Unit 6
    animal: animal
    Athenae: Athens
    atque: and
    ac: and
    aurora: dawn
    
    % Unit 7
    amo: love
    amor: love
    annus: year
    Asia: Asia
    i-compile na ang latin.cpp then i-save na ang file nga latin.txt sa directory kung asa ang executable file nakabutang nga resulta sa pag-compile. after ana pwede na siya ma-run, kanang latin.txt kay mao nay input file sa executable. after ana ug run, naay file nga ma-create same directory sa executable nga ang filename kay english.txt which is the final output. instead nga sa screen nko gi-output kay sa file na lang nko gi-save kay i'm sure kabalo nka unsaon pag-output sa screen, mas beneficial kung sa file padulong kay at least intro pud sa file input/output, dili ra kay puro data structs. anyway, dali ra man pud na usbon kung ganahan ka.

    i-check lang kung mao ba ang output. gcc sa linux akong gigamit pero mo-run na bisan asa basta ang c++ compiler nga gamiton kay modern lang. dili katong panahon pa sa mga dinosaur. joke.

    ako na lang pud gi-upload ang files nga naka-zip na... http://www.mediafire.com/?v8mbac35b1da0g6 <-- download then unzip, then i-open ang latin.cpp using dev-c++, compile then run.

  11.    Advertisement

Page 1 of 2 12 LastLast

Similar Threads

 
  1. Replies: 5
    Last Post: 10-25-2010, 11:25 PM
  2. Looking for a private tuitor in JAVA and DATA Structure PROGRAMMING
    By cyepoohs in forum Networking & Internet
    Replies: 2
    Last Post: 10-25-2010, 11:14 PM
  3. kinsay naay idea sa data structure?
    By reyarita in forum Programming
    Replies: 0
    Last Post: 09-26-2009, 06:30 PM
  4. Site: Data Structure Tut
    By intheb0x in forum Programming
    Replies: 4
    Last Post: 08-13-2009, 04:23 PM
  5. Replies: 17
    Last Post: 11-01-2008, 10:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top